Question: Sorting a linked list and Inserting a new element in descending order in C programming Given: typedef struct person { unsigned short age; char *name;
Sorting a linked list and Inserting a new element in descending order in C programming
Given:
typedef struct person {
unsigned short age; char *name; // first name, no spaces struct height {int feet; int inches;} vertical; int idenifier; // unique identifier struct person *next; } person_t;
The linked list should be sorted in descending order depedning on the age.
Say, a file has the data below
31 Alice 5 9 111111 64 Bob 6 11 555555 22 Mira 6 3 7171
The first element of the list is pointed to by person_t *head which in the example would be 64 Bob 6 11 555555.
After sorting, the file output should be
64 Bob 6 11 555555
31 Alice 5 9 111111
22 Mira 6 3 7171
Given : void insert_plist(unsigned short a, char *b, int c, int d, int e);
Then we want to insert a new person in the linked list, the position of the person to be inserted depends on the descending order.
Say if we want to insert 48 Aaron 6 10 77778 into the linked list above. The element would be placed in the second since the age 48 is the second largest number in the list.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
