1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
typedef struct Student
{
char firstname,lastname,fullname;
float t1,t2,t3;
}Student;
const int MAXSTUDENTS = 5;
void qsort(Student theStu[],int first,int last);
int main (void)
{
struct Student theStu;
qsort(theStu[],0,MAXSTUDENTS - 1);
}
void qsort(Student theStu,int start,int finish)
{
int left=start,
right=finish,
pivot=theStu.lastname[(start+finish)/2];
while (left < right) {
while (theStu.lastname[left] < pivot) left++;
while (theStu.lastname[right] > pivot) right--;
if (left <= right) {
int temp = theStu.lastname[left];
theStu.lastname[left] = theStu.lastname[right];
theStu.lastname[right] = temp;
left++;
right--;
}
}
if (start < right) qsort(theStu,start,right);
if (left < finish) qsort(theStu,left,finish);
}
|