看了你的排序,链表进行,你只能对数值进行排序,但是链表的顺序你就不能颠倒,后果可以想象
Maybe
void sort(PSC phead) //链表的排序 { PSC p1, p2,p3,p4,p; p1=phead; int td; char tc[50]; p2 = p1->pnext; p3 = (PSC)malloc(sizeof(SC)); while(p1->pnext != NULL) { p1 = p1->pnext; } p4 = p1; p1->pnext = p3; p3->pnext = NULL; p1=phead; do { p2 = p1; while(p2->pnext != NULL) { if(p1->score < p2->score) { td = p1->score; p1->score = p2->score; p2->score = td; strcpy(tc, p1->name); strcpy(p1->name, p2->name); strcpy(p2->name, tc); } p2 = p2->pnext; } p1 = p1->pnext; }while(p1->pnext != NULL); p4->pnext = NULL; free(p3); p = phead; // 输出 printf("\n\t\t排序后:\n"); while(p!= NULL) { printf("\t\t\t%s\t\t%d\n", p->name, p->score); p = p->pnext; } system("pause"); } void exit0(PSC phead) { PSC p1, p2; p1=phead; while( p1!=NULL) { p2=p1->pnext; free(p1); p1=p2; } }