Take the orderhw.c file and modify the code to build a linked list that is sorted by the address field not the name field as it is currently written!
Using the following code
void prntlist(LISTREC *liststart)
/*argument is a
pointer to type LISTREC*/
{ /*begin function*/
while (liststart != NULL)
{ /*begin while*/
printf("%s\n",liststart->info.name);
liststart =
liststart->link;
} /*end while*/
} /* end function prntlist*/
Draw the label pictures to show what is going on.
ANSWER :
The sorting logic is we compare the address of the adjacent nodes and swap the nodes if the first node address has higher value. for example if the address of first node is "zurich" and address of second node is "australia" then the 2 nodes are swapped because the "Australia" starts with A and Zurich started with Z.So the node with Australia as address comes first than the node with address as Zurich.
Get Answers For Free
Most questions answered within 1 hours.