链表怎么排序啊,老是出错
程序代码:
void browsenum() //按编号浏览 冒泡排序 { BOOK *p, *p1, *p2, *p3, *head; BOOK h,t; head = read(); if(head = NULL) {printf("空文件!\n"); main(); exit(0);} h.next = head; p=&h; //记录头结点 while(p->next!=NULL) { p->next; } p=p->next=&t; //记录为尾节点 while(p!=h.next){ p3 = &h; p1 = p3->next; p2 = p1->next; while(p2!=p){ if(p1->num > p2->num){ p1->next=p2->next; p2->next=p1; p3->next=p2; p3 = p2; p2=p1->next; } else{ p3=p1; p1=p2; p2=p2->next; } } p=p1; } while(p->next!=&t) { p=p->next; } p=p->next=NULL; printfnum(h.next); } void printfnum(BOOK *h) { int n = 15; BOOK *ptr; printf("\n\t\t\t〓〓〓〓〓图书管理系统〓〓〓〓〓\n\n"); printf("\t\tnumber\t\t writer\t\t name\t\t price\n"); for(ptr=h; ptr; ptr= ptr->next){ n++; printf("\t\t%d\t\t %s\t\t %s\t\t %.2f\n", ptr->num, ptr->writer, ptr->name, ptr->price); if(n%15 == 0){ printf("press any to continue~~\n"); getch(); printf("\t\tnumber\t\t writer\t\t name\t\t price\n"); } } printf("输出完毕! 按任意键回主菜单!\n"); getch(); }