Create two linked lists each having ten node.the first list has a pointer called
ID: 3658569 • Letter: C
Question
Create two linked lists each having ten node.the first list has a pointer called UNO to the first node and the second list has a pointer called DUO to the first node. The lists are to be sorted BY GPA as you create them. The data in the lists will consist of a last name and GPA .Print out each sorted list after you create themExplanation / Answer
typedef struct d{ char *lastName; double gpa; struct d* next; lastname =(char *)malloc(20*sizeof(char)); }list; list *makenode(list * a,char *b;,double gpa){ if(a == null){ a = (list *)malloc(sizeof(list)); a->lastName = b; a->gpa = gpa; a->next = null; return a; } else{ list *b =a; list *prev = a; while(b->next != null){ if(b->gpa > gpa){ prev = b; b = b ->next; } else{ list*c = (list*)malloc(sizeof(list)); c->lastName = b; c->gpa = gpa; c->next = b; prev->next = c; return a; } } list*c = (list*)malloc(sizeof(list)); c->lastName = b; c->gpa = gpa; c->next = null; return a; } } list *delete(list*a,double gpa){ list*c =a; list *prev = a; while(c ->next!=null){ if(c ->gpa > gpa){ prev = c; c->next =next; } else{ prev->next = null; } return c; } } list *merge(list *a,list*b){ list *c = a; list *prev = a; while(c ->next!= null){ prev = c; c =c ->next; } prev->next =b; return a; } int main(){ int i = 0; list *a,*b; char *p; double r; printf("Ebnter lastname, gpa respectively") for(i = 0; i < 10;i++){ scanf("%s",p); scanf("%lf",r) a = makenode(a,p,r); } for(i = 0; i < 10;i++){ scanf("%s",p); scanf("%lf",r) b= makenode(a,p,r); } a = delete(a,3.5); b = delete(b,2); a = merge(a,b); }Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.