hey im new with this all, im doing assigmnet for class, what it does it gets a list of students and their grade, splits them to fail and pass, and at the end it should each group be ordered by lexicographic order, plz help me out, i assume or the swap or the find_min or the sort r wrong, because the rest of the prog i've checked and it worked, i havent posted all the code but assumes the func that are there are working
Code:#include <stdio.h> #include <stdlib.h> #include<string.h> #define MAX_NAME_SIZE 30 typedef struct student_node { char name[MAX_NAME_SIZE]; double grade; struct student_node* next; }Student; Student *read_students(); /*gets list of students from user*/ void print_list(Student *pHead); /*prints list of students from user*/ void split_list(Student *pHead, Student** pass, Student** fail); /*splits students list to fail&pass*/ void split_cpy_list(Student *pHead, Student** pass, Student** fail); /*splits students list to fail&pass*/ Student *sort_list(Student *pHead); /*sots students list lexicographi*/ void swap(Student *swp1, Student *swp2); /*swaps between structs*/ Student *find_min(Student *pHead); /*finds the struct where name is with smallest lexicographi*/ int main() { Student *pass1=NULL, *fail1=NULL; Student *list = read_students(); printf("\n"); print_list(list); split_list(list, &pass1, &fail1); printf("\n students above 60: \n"); sort_list(pass1); print_list(pass1); printf("\n students bellow 60: \n"); sort_list(fail1); print_list(fail1); free(list); return 0; } } void swap(Student *swp1, Student *swp2) { Student *swp_tmp = NULL; strcpy(swp_tmp->name,swp1->name); swp_tmp->grade = swp1->grade; strcpy(swp1->name,swp2->name); swp1->grade = swp2->grade; strcpy(swp2->name,swp_tmp->name); swp2->grade = swp_tmp->grade; } Student *find_min(Student *pHead) { Student *tmp_find = NULL; tmp_find = pHead; while(pHead != NULL) { if(strcmp(pHead->name,tmp_find->name)<0) *tmp_find = *pHead; pHead = pHead->next; } return tmp_find; } Student *sort_list(Student *pHead) { Student *tmp_sort = NULL; tmp_sort = pHead; while(tmp_sort != NULL) { if(strcmp(tmp_sort->name, find_min(tmp_sort->next)->name)>0) swap(tmp_sort,find_min(tmp_sort->next)); tmp_sort=tmp_sort->next; } return tmp_sort; }



LinkBack URL
About LinkBacks



