write a program that that creates a linked list of a list of ints bubble sorted
ID: 3656127 • Letter: W
Question
write a program that that creates a linked list of a list of ints bubble sorted from a txt fileExplanation / Answer
#include #include struct student { int com,com_use; //[com:Computer_grades] [com_use:Laboratory_grades] int num,total; // [num:Seat_number] [total:the sum of math and english grades] struct student * next; }; struct classes { char t; // [t:Class_Character] struct student * point; struct classes * next; }; void sl_sort(struct classes **,struct student **); // The function of "Selection Sort" int main() { FILE *data; char temp; int first=1; int num_t,com_t,com_u_t; int stu_count=0; struct student *stu_head,*stu_pt,*stu_pre,*stu_cur; struct classes *cla_head,*cla_pt,*cla_pre,*cla_cur; stu_head=NULL; cla_head=NULL; data=fopen("final.txt","r"); while ((fscanf(data,"%c %d %d %d ",&temp,&num_t,&com_t,&com_u_t)) != EOF) { stu_pt=(struct student *)malloc(sizeof(struct student)); stu_pt->num=num_t; stu_pt->com=com_t; stu_pt->com_use=com_u_t; stu_pt->total=com_t+com_u_t; stu_pt->next=NULL; if (first == 1) { stu_head=stu_pt; cla_head=(struct classes *)malloc(sizeof(struct classes)); cla_head->t=temp; cla_head->point=stu_head; cla_head->next=NULL; first=0; } else { cla_cur=cla_head; while (cla_cur != NULL) { if (cla_cur->t == temp) { break; } cla_cur=cla_cur->next; } if (cla_cur == NULL) { cla_pt=(struct classes *)malloc(sizeof(struct classes)); cla_pt->t=temp; cla_pt->point=stu_pt; cla_pt->next=NULL; cla_pre=cla_head; while (cla_pre->next != NULL) { cla_pre=cla_pre->next; } cla_pre->next=cla_pt; } else { stu_pre=cla_cur->point; while (stu_pre->next != NULL) { stu_pre=stu_pre->next; } stu_pre->next=stu_pt; } } } fclose(data); sl_sort(&cla_head,&stu_head); return 0; } void sl_sort(struct classes **cla_head,struct student **stu_head) { struct classes *cla_temp,*cla_cur,*cla_pre,*cla_start,*cla_add_at; int cla_start_count=0,i; cla_start=*cla_head; while (1) { if (cla_start_count != 0) { cla_start=*cla_head; for (i=cla_start_count;i>0;i--) { cla_start=cla_start->next; } } if (cla_start->next = NULL) { break; } cla_cur=cla_start; cla_temp=cla_start; while (cla_cur != NULL) { if (cla_cur->t t) { cla_temp=cla_cur; } cla_cur=cla_cur->next; } cla_pre=*cla_head; while (cla_pre->next != cla_temp) { cla_pre=cla_pre->next; } cla_pre->next=cla_temp->next; if (cla_start_count != 0) { cla_add_at=*cla_head; while (cla_add_at->next != cla_start) { cla_add_at=cla_add_at->next; } cla_temp->next=cla_pre; cla_add_at->next=cla_temp; } else { cla_temp->next=*cla_head; *cla_head=cla_temp; } cla_start_count=cla_start_count+1; } }Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.