Advertisement
Guest User

Untitled

a guest
Dec 7th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. void insert(Dictionary D, char* k, char* v){
  2. int hashNum;
  3. char* hashValue;
  4. Node prev, N, temp;
  5.  
  6. if(D == NULL){
  7. fprintf(stderr,"Dictionary Error: calling insert() on NULL Dictionary reference\n");
  8. exit(EXIT_FAILURE);
  9. }
  10. hashNum = hash(k); //gets the index where k is
  11.  
  12. hashValue = lookup(D, k); //returns key you were looking for after looking it up to check if it's there
  13. if (hashValue == NULL) {
  14. N = newNode(k, v);
  15. if (D->hashTable[hashNum] == NULL) {
  16. D->hashTable[hashNum] = N;
  17. } else {
  18. N->next = D->hashTable[hashNum];
  19. D->hashTable[hashNum] = N;
  20. }
  21. } else {
  22. N = D->hashTable[hashNum];
  23. while (N != NULL) {
  24. if (strcmp(N->key, k) == 0) {
  25. N->value = v;
  26. break;
  27. }
  28. N = N->next;
  29. }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement