Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void LIST_ENTRIES(entry *head){
- //make a pointer to entry called entry_ptr and initialize it to
- //be the head node
- entry *entry_ptr = entry_head;
- if (entry_ptr == NULL) {
- printf("no entries\n\n");
- }
- //iterate through the list and print all the keys in it
- while(entry_ptr != NULL){
- printf("%s ", entry_ptr->key);
- //make a pointer to value and make it the head of the values
- value *value_ptr = head->values;
- printf("[");
- //traverse the list to print all the values
- while(value_ptr != NULL){
- printf("%d ", value_ptr->value);
- value_ptr = value_ptr->next;
- }
- printf("]\n\n");
- entry_ptr = entry_ptr->next;
- }
- }
- //GET command
- void GET(char *key){
- //make a pointer to entry called entry_ptr and initialize it to
- //be the head node
- entry *entry_ptr = entry_head;
- int has_key = 0;
- int first_value = 1;
- if (entry_ptr == NULL) {
- printf("no such key\n\n");
- return;
- }
- //traverse the list and when they given key matches the node,
- //print all the values of that key
- while(entry_ptr != NULL){
- if(strcmp(entry_ptr->key, key) == 0 ){
- has_key = 1;
- value *value_ptr = entry_ptr->values;
- printf("[");
- while(value_ptr != NULL){
- if (first_value) {
- printf("%d", value_ptr->value);
- value_ptr = value_ptr->next;
- first_value = 0;
- } else {
- printf(" %d", value_ptr->value);
- value_ptr = value_ptr->next;
- }
- }
- printf("]\n\n");
- return;
- }
- entry_ptr = entry_ptr->next;
- }
- if (!has_key) {
- printf("no such key\n\n");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement