关于排序的问题
程序代码:
#include<stdio.h> #include<stdlib.h> #include<string.h> struct stu{ int num; struct stu * next; }; void creat(); struct stu *p, *q , *head, *tail; int main(void) { struct stu * head = NULL; creat(); return 0; } void creat() { int num, n = 0, i, j; int ptr; head = tail = NULL; int size = sizeof(struct stu); printf("input 0 end input and print link!\n"); printf("input num:\n"); scanf("%d",&num); do{ p = (struct stu *)malloc(size); p->num = num; if(head == NULL) head = p; else tail->next = p; tail = p; p->next = NULL; printf("input number:\n"); scanf("%d",&num); n++; }while(num != 0); p = head; q = p->next; for(i = 1;i< n; i++){ for(j = 0; j<=n-i;j++){ if(p->num >= q->num){ ptr = p->num; p->num = q->num; q->num = ptr; } p=q; q=q->next; } } for(p = head;p;p=p->next) printf("%d",p->num); }
问什么不能输出呢?