Question: #include #include #include typedef struct dict_list { char* key; char* val; struct dict_list* next; } dict_list_t; typedef struct dict { dict_list_t* head; size_t size; }

#include  #include  #include  typedef struct dict_list { char* key; char* val; struct dict_list* next; } dict_list_t; typedef struct dict { dict_list_t* head; size_t size; } dict_t; void dict_del (dict_t* dict, const char* key); int main() { dict_t dictionary; dictionary.head = NULL; dictionary.size = 0; dict_list_t *el1 = (dict_list_t*) malloc(sizeof(dict_list_t)); el1->key = "key1"; el1->val = "value1"; el1->next = NULL; dictionary.head = el1; dictionary.size++; dict_list_t *el2 = (dict_list_t*) malloc(sizeof(dict_list_t)); el2->key = "key2"; el2->val = "value2"; el2->next = NULL; el1->next = el2; dictionary.size++; char *value = dict_get(&dictionary, "key1"); if (value != NULL) { printf("Value for key 'key1': %s ", value); } else { printf("Key 'key1' not found in the dictionary "); } value = dict_get(&dictionary, "key3"); if (value != NULL) { printf("Value for key 'key3': %s ", value); } else { printf("Key 'key3' not found in the dictionary "); } return 0; } 

dict_del Finally, you should implement:

This function goes through dict searching for key, if it finds it, it should delete the corresponding key/value pair. The memory allocated for the element and its key/value pair should be free'd. If the key does not exist, this function does nothing.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!