Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Mobile Communications

Authors: Jochen Schiller

2nd edition

978-0321123817, 321123816, 978-8131724262

More Books

Students also viewed these Programming questions

Question

How do you further improve the product quality?

Answered: 1 week ago