Hello everyone, I have a program where I have to sort array of structures by the month of the birthday. I have a function to do that and it looks that it must work but the program stops when it comes to that function. I will be very appriciated if someone can tell me where i am wrong.
Thank you
Here is the function, I am using bubble sort.
Code:void sort_array_by_month(void) { struct sStudent Temp; int i, n, swap; do { swap=0; for(i=0; i<3; ++i)//bubble sort { if(Algebra[i].birthday.month>Algebra[i+1].birthday.month) Temp.birthday.month=Algebra[i].birthday.month; // temp[Count]=Array[count+1] Temp.birthday.day=Algebra[i].birthday.day; Temp.birthday.year=Algebra[i].birthday.year; for(n=0; Algebra[i].first_name[n]!=0; ++n) { Temp.first_name[n]=Algebra[i].first_name[n]; Temp.first_name[n]='\0'; } for(n=0; Algebra[i].last_name[n]!=0; ++n) { Temp.last_name[n]=Algebra[i].last_name[n]; Temp.last_name[n]='\0'; } Algebra[i].birthday.day=Algebra[i+1].birthday.day; //Array[Count]=Array[Count+1] Algebra[i].birthday.month=Algebra[i+1].birthday.month; Algebra[i].birthday.year=Algebra[i+1].birthday.year; for(n=0; Algebra[i].first_name[n]!=0; ++n) { Algebra[i].first_name[n]=Algebra[i+1].first_name[n]; Algebra[i].first_name[n]='\0'; } for(n=0; Algebra[i].last_name[n]!=0; ++n) { Algebra[i].last_name[n]=Algebra[i+1].last_name[n]; Algebra[i].last_name[n]='\0'; } Algebra[i+1].birthday.month=Temp.birthday.month; //Array[Count+1]=Temp Algebra[i+1].birthday.day=Temp.birthday.day; Algebra[i+1].birthday.year=Temp.birthday.year; for(n=0; Algebra[i].first_name[n]!=0; ++n) { Algebra[i+1].first_name[n]=Temp.first_name[n]; Algebra[i+1].first_name[n]='\0'; } for(n=0; Algebra[i].last_name[n]!=0; ++n) { Algebra[i+1].last_name[n]=Temp.last_name[n]; Algebra[i+1].last_name[n]='\0'; } swap=1; } }while(swap!=0); }



LinkBack URL
About LinkBacks




Your bubblesort shrinks by a factor of 10X.