Пример #1
0
void RemoveDuplicate2(Node* head)
{
    Node* p = head->next;

    if(p == NULL)
        return;

    HashTable tbl;

    while(p->next!=NULL)
    {
        Node* t = NULL;

        if(tbl.Contains(p->next->val))
        {
            p->next = p->next->next;
        }
        else
        {
            tbl.AddEntry(p->next->val);
            p = p->next;
        }
    }


}
Пример #2
0
void RemoveDuplicate(Node* head)
{
    HashTable tbl;
    Node* prev = head;
    Node* curr = head;
    while(curr!=NULL)
    {
        Node* t = NULL;
        if(tbl.Contains(curr->val))
        {
            prev->next = curr->next;
            t = curr;
        }
        else
        {
            tbl.AddEntry(curr->val);
            prev = curr;
        }
        curr = curr->next;
    }
}
Пример #3
0
int main(int argc, const char * argv[])
{
    HashTable * ht = iHashTable.Create(64, sizeof(int));

    const char test_key0[] = "test_key0";
    const char test_key1[] = "test_key1";
    const char test_key2[] = "test_key2";
    const char invalid_key[] = "invalid_key";

    int a = 1;
    int b = 2;
    int c = 3;

    // Test Insert & Retrieve

    printf ("Test Insert & Retrieve...\n");
    
    ht->Insert(ht, (void*)test_key0, strlen(test_key0), &a);
    ht->Insert(ht, (void*)test_key1, strlen(test_key1), &b);
    ht->Insert(ht, (void*)test_key2, strlen(test_key2), &c);

    assert(ht->cnt == 3);

    int data;

    ht->Retrieve(ht, (void*)test_key0, strlen(test_key0), &data);
    assert(data == a);
    
    ht->Retrieve(ht, (void*)test_key1, strlen(test_key1), &data);
    assert(data == b);

    ht->Retrieve(ht, (void*)test_key2, strlen(test_key2), &data);
    assert(data == c);

    int ret = ht->Retrieve(ht, (void*)invalid_key, strlen(invalid_key), &data);

    assert(ret == E_NOT_FOUND);
    assert(ht->cnt == 3);

    // Test replacement

    printf ("Test Replace...\n");

    ht->Insert(ht, (void*)test_key0, strlen(test_key0), &b);
    assert(ht->cnt == 3);

    ht->Retrieve(ht, (void*)test_key0, strlen(test_key0), &data);
    assert(data == b);

    // Test Continas, Find & Erase

    printf ("Test Contains, Find, Erase...\n");

    void *key_ret = NULL;
    size_t key_len;

    assert(ht->Contains(ht, &c) == RET_OK);
    
    ht->Find(ht, &c, &key_ret, &key_len);
    assert(key_ret != NULL && key_len != 0);
    ht->Erase(ht, key_ret, key_len);

    free (key_ret);

    assert(ht->cnt == 2);

    assert(ht->Contains(ht, &c) == E_NOT_FOUND);
    ret = ht->Retrieve(ht, (void*)test_key2, strlen(test_key2), &data);
    assert(ret == E_NOT_FOUND);

    // Test destroy
    printf ("Test Destroy...\n");
 
    ht->Destroy(ht);

    printf("All tests passed\n");
    
}
Пример #4
0
//********MAIN
int main()
{
	//calling on HashTable class
	HashTable hashTable;
	FillTableWithDictionaryWords(&hashTable);
	

	//A temp char array to put lines of the document in
	//fstream: Stream class to both read and write from/to files.
	//calls on document from stored on e drive
	char temp[512];
	std::fstream instream;
	instream.open(DOCUMENT);

	cout << "Misspelled words are:" << endl << endl;

	//THIS IS FOR EACH IN THE MIS-SPELLED DOCUMENT
	while (instream >> temp)
	{
		int i = 0;
		char * line = "";

		while (temp[i])
		{
			//THIS ROUTINE STRIPS PUNCATION
			//if the char is a LETTER, then add it to the 'line' string.
			//we can tell by looking at the AASCII values.
			//lines 97 to 122 are lower case
			//lines 65 to 90 are upper case
			if ((temp[i] < 123 && temp[i] > 96) || (temp[i] < 91 && temp[i] > 64))
			{
				//get the length of the line
				int len = strlen(line);

				//create a new line array thats larger then the line array
				char * newArray = new char[len + 2];

				//copy the line into it
				strcpy(newArray, line);

				//add the new char to the end of the line array
				newArray[len] = temp[i];

				//add the string terminating character 
				newArray[len + 1] = '\0';

				//assign the line array the new line array
				line = newArray;
			}
			i++;
		}

		//AFTER PRINTING MIS-SPELLED WORD
		//check that the string is longer then 0 before checking
		//if the tree contains it.
		//if it does not contain it, then print it
		if (strlen(line) > 0 && !hashTable.Contains(line))
		{
			std::cout << line << std::endl;
		}
	}
	
	//callingh the Printable function
	std::cout << std::endl << "Hastable:" << std::endl;

	hashTable.PrintTable();


	int i;
	cin >> i;
	return 0;
}