呵呵,//动态链表排序 #include <stdio.h> #include <stdlib.h> #include <malloc.h> #define LEN sizeof(struct order) struct order { int num; struct order* next; }; int main(void) { int M, i, j; struct order *head; struct order *p1, *p2, *p3; while(scanf("%d", &M) && M != 0) { head=(struct order *)malloc(LEN); scanf("%d", &head -> num); head->next = NULL; for(i=1; i<M; i++) { p1=(struct order*)malloc(LEN); scanf("%d", &p1->num); p2=head; for(j=0; j<i; j++) { if(p2->num >= p1->num) { head = p1; p1->next = p2; break; } else if(p2->num < p1->num) { if(p2->next == NULL) { p2->next = p1; p1->next = NULL; break; } else if((p2->next)->num >= p1->num) { p1->next = p2->next; p2->next = p1; break; } else { p2=p2->next; } } } } p1=head; for(i=0; i<M; i++) { printf("%d", p1->num); if(i!=M) printf(" "); else printf("/n"); p1 = p1->next; } } system("pause"); return 0; } 刚看了链表,写一个试一下~~