Question: please fix this code. I want it to be (kelly, 12) -> (Rob, 32) -> (tom, 82) in that order. C programming. doubly link list

please fix this code. I want it to be (kelly, 12) -> (Rob, 32) -> (tom, 82) in that order.
C programming. doubly link list
please fix this code. I want it to be (kelly, 12) ->
(Rob, 32) -> (tom, 82) in that order. C programming. doubly link
list vouWN home > steven > Desktop > dlink.c #include 2 #include
3 #include 4 #include 5 6 | 7 8 struct Node {

vouWN home > steven > Desktop > dlink.c #include 2 #include 3 #include 4 #include 5 6 | 7 8 struct Node { 9 char *name; 10 int id; 11 struct Node *next; 12 struct Node *prev; 13 }; 14 15 struct List { 16 struct Node *head; 17 struct Node *tail; 18 int count: 19 }; 20 21 struct Node *create_node(char *name, int id) { 22 struct Node node = malloc(sizeof(struct Node)); if (node == NULL) { 24 fprintf (stderr, *es: Couldn't create memory for the node; %s ", "Linkedlist", strerror(errno)): 25 exit(-1); 26 } node->name = strdup(name); node->id = id; node->next = NULL; 30 node->prev = NULL; 31 return node; 32 } 33 34 struct List *create list( { 35 struct List list = malloc(sizeof(struct List)); 36 if (list == NULL) { 37 fprintf (stderr, ***: couldn't create memory for the list; $s ", "linkedlist", strerror(errno)); 38 exit(-1); 39 40 list->head = NULL; 41 list->tail = NULL; 42 list->count = 0; 43 return list; 44 } Bubumm void print_list (struct List *list) { struct Node *ptr = list->head; while (ptr != NULL) { if (ptr != list->head) { printf("->"); } printf("%s,&d)", ptr->name, ptr->id); ptr = ptr->next; } printf(" Total items: %d ", list->count); } void insert_sorted (struct Node *node, struct List *list) { if(list->head NULL && list->tail NULL) { list->head node; list->tail node; }else if (list->head->id > node->id) { 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 = 00 ONM node->next = list->head; list->head->prev = node; list->head node; }else { /*list->tail->next = node; node->prev list->tail; list->tail = node; */ struct Node *tempo list->head; struct Node *tem; while(tempo->id id && tempo != NULL) { tem = tempo; tempo = tempo->next; } node->prev tempo->prev; node->next tempo; tempo->prev->next = node; tempo ->prev = node; } } 42 44 45 46 47 10 int main(int argc, char *argv[]) { struct List *list = create_list(); struct Node *tmp = NULL; = tmp = create_node("Kelly", 12); insert_sorted (tmp, list); 11 Add functionality to keep track of the number of elements in the list tmp = create_node("Tom", 82); insert_sorted (tmp, list); tmp = create_node ( "Rob", 32); insert sorted (tmp, list); print_list(list); vouWN home > steven > Desktop > dlink.c #include 2 #include 3 #include 4 #include 5 6 | 7 8 struct Node { 9 char *name; 10 int id; 11 struct Node *next; 12 struct Node *prev; 13 }; 14 15 struct List { 16 struct Node *head; 17 struct Node *tail; 18 int count: 19 }; 20 21 struct Node *create_node(char *name, int id) { 22 struct Node node = malloc(sizeof(struct Node)); if (node == NULL) { 24 fprintf (stderr, *es: Couldn't create memory for the node; %s ", "Linkedlist", strerror(errno)): 25 exit(-1); 26 } node->name = strdup(name); node->id = id; node->next = NULL; 30 node->prev = NULL; 31 return node; 32 } 33 34 struct List *create list( { 35 struct List list = malloc(sizeof(struct List)); 36 if (list == NULL) { 37 fprintf (stderr, ***: couldn't create memory for the list; $s ", "linkedlist", strerror(errno)); 38 exit(-1); 39 40 list->head = NULL; 41 list->tail = NULL; 42 list->count = 0; 43 return list; 44 } Bubumm void print_list (struct List *list) { struct Node *ptr = list->head; while (ptr != NULL) { if (ptr != list->head) { printf("->"); } printf("%s,&d)", ptr->name, ptr->id); ptr = ptr->next; } printf(" Total items: %d ", list->count); } void insert_sorted (struct Node *node, struct List *list) { if(list->head NULL && list->tail NULL) { list->head node; list->tail node; }else if (list->head->id > node->id) { 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 = 00 ONM node->next = list->head; list->head->prev = node; list->head node; }else { /*list->tail->next = node; node->prev list->tail; list->tail = node; */ struct Node *tempo list->head; struct Node *tem; while(tempo->id id && tempo != NULL) { tem = tempo; tempo = tempo->next; } node->prev tempo->prev; node->next tempo; tempo->prev->next = node; tempo ->prev = node; } } 42 44 45 46 47 10 int main(int argc, char *argv[]) { struct List *list = create_list(); struct Node *tmp = NULL; = tmp = create_node("Kelly", 12); insert_sorted (tmp, list); 11 Add functionality to keep track of the number of elements in the list tmp = create_node("Tom", 82); insert_sorted (tmp, list); tmp = create_node ( "Rob", 32); insert sorted (tmp, list); print_list(list)

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 Databases Questions!