Question
Use data structure to show how to add a created node to the front of the list. The answer is more about a graphical representation
Use data structure to show how to add a created node to the front of the list. The answer is more about a graphical representation of how to add a node to the front of a list again, and not about coding (in other words, about visuals).
code:
void listinsert(ENTRY newentry,LISTREC *liststart) { LISTREC *last,*next; next = liststart;
while ((strcmp(newentry.name,next->info.name)> 0) && (next->link != NULL)) { last = next; next = next->link; } /*end while*/
if (strcmp(newentry.name,next->info.name) == 0) /*if both are same*/ next->info = newentry; /*updates*/ else if (strcmp(newentry.name,next->info.name) < 0) { last->link = (LISTREC*)malloc(sizeof(LISTREC)); /*creates new node*/ last->link->info=newentry; last->link->link = next; } else { next->link = (LISTREC*)malloc(sizeof(LISTREC)); next->link->info = newentry; next->link->link = NULL; } /* end else */ printf(" After insertion, linked list: "); prntlist(liststart); } /* end function listinsert*/
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started