Advertisement
Guest User

Untitled

a guest
Nov 12th, 2019
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include "Dictionary.h"
  4.  
  5. typedef struct NodeObj{
  6. char* key;
  7. char* value;
  8. } NodeObj;
  9.  
  10. typedef NodeObj* Node;
  11.  
  12. Node newNode(char* k, char* v){
  13. Node N = malloc(sizeof(NodeObj));
  14. N->key = k;
  15. N->value = v;
  16. return N;
  17. }
  18.  
  19. void freeNode(Node* pN){
  20. if(pN != NULL && *pN != NULL){
  21. free(*pN);
  22. *pN = NULL;
  23. }
  24. }
  25.  
  26. void freeAllNodes(Node H){
  27. if(H != NULL){
  28. freeAllNodes(H->next);
  29. freeNode(&H);
  30. }
  31. }
  32.  
  33. typedef struct DictionaryObj*{
  34. Node head;
  35. int size;
  36. } DictionaryObj;
  37.  
  38. Dictionary newDictionary(){
  39. Dictionary D = malloc(sizeof(DictionaryObj));
  40. D->head = NULL;
  41. D->size = 0;
  42. }
  43.  
  44. void freeDictionary(Dictionary* pD){
  45. if(pD != NULL && *pD != NULL){
  46. makeEmpty(*pD);
  47. free(*pD);
  48. *pD = NULL;
  49. }
  50. }
  51.  
  52. Node findKey(Dictionary* D, char* k){
  53. Node N = D->head;
  54. for(int i = 0; i < D->size; i++){
  55. if(N == k){
  56. return N;
  57. }
  58. N = N->next;
  59. }
  60.  
  61. return NULL;
  62. }
  63.  
  64. int size(Dictionary D){
  65. if(D == NULL){
  66. fprintf(stderr, "Dictionary Error: size() called on NULL IntegerList reference.\n");
  67. exit(EXIT_FAILURE);
  68. }
  69.  
  70. return D->size;
  71. }
  72.  
  73. char* lookup(Dictionary D, char* k){
  74. if(D == NULL){
  75. fprintf(stderr, "Dictionary Error: lookup() called on NULL IntegerList reference.\n");
  76. exit(EXIT_FAILURE);
  77. }
  78.  
  79. if()
  80. }
  81.  
  82. void insert(Dictionary D, char* k, char* v){
  83. if(D == NULL){
  84. fprintf(stderr, "Dictionary Error: insert() called on NULL IntegerList reference.\n");
  85. exit(EXIT_FAILURE);
  86. }
  87. }
  88.  
  89. void delete(Dictionary D, char* k){
  90. if(D == NULL){
  91. fprintf(stderr, "Dictionary Error: delete() called on NULL IntegerList reference.\n");
  92. exit(EXIT_FAILURE);
  93. }
  94. }
  95.  
  96. void makeEmpty(Dictionary D){
  97. if(D == NULL){
  98. fprintf(stderr, "Dictionary Error: makeEmpty() called on NULL IntegerList reference.\n");
  99. exit(EXIT_FAILURE);
  100. }
  101. }
  102.  
  103. char* DictionaryToString(Dictionary D){
  104. if(D == NULL){
  105. fprintf(stderr, "Dictionary Error: DictionaryToString() called on NULL IntegerList reference.\n");
  106. exit(EXIT_FAILURE);
  107. }
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement