Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void insert(Dictionary D, char* k, char* v){
- int hashNum;
- char* hashValue;
- Node prev, N, temp;
- if(D == NULL){
- fprintf(stderr,"Dictionary Error: calling insert() on NULL Dictionary reference\n");
- exit(EXIT_FAILURE);
- }
- hashNum = hash(k); //gets the index where k is
- hashValue = lookup(D, k); //returns key you were looking for after looking it up to check if it's there
- if (hashValue == NULL) {
- N = newNode(k, v);
- if (D->hashTable[hashNum] == NULL) {
- D->hashTable[hashNum] = N;
- } else {
- N->next = D->hashTable[hashNum];
- D->hashTable[hashNum] = N;
- }
- } else {
- N = D->hashTable[hashNum];
- while (N != NULL) {
- if (strcmp(N->key, k) == 0) {
- N->value = v;
- break;
- }
- N = N->next;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement