急!!求c语言单链表冒泡排序的详细流程图

2024-11-22 19:44:57
推荐回答(2个)
回答(1):

#include #include struct number { int num; struct number *next; }; void main() { struct number *head; struct number *p1,*p2,*p,*p3,*p4; int n=0,m,i,j; p1=p2=(struct number *)malloc(sizeof(struct number)); printf("\nWang jianfei 060806110006\n\n\n"); printf("Please enter the number: \n"); scanf("%d",&p1->num); head=NULL; while(p1->num!=NULL) { n=n+1; if(head==NULL) head=p1; else p2->next=p1; p2=p1; p1=(struct number *)malloc(sizeof(struct number)); scanf("%d",&p1->num); } p2->next=NULL; p=head; for(p4=head;p4!=NULL;p4=p4->next) { for(p3=head;p3->next!=NULL;p3=p3->next) { if(p4->num>p3->num) { m=p4->num; p4->num=p3->num; p3->num=m; } } p=head; } printf("\nNow,there %d numbers are: ",n); p=head; printf("\n"); if(head!=NULL) do { printf("%5d ",p->num); p=p->next; }while(p!=NULL); printf("\n"); getch(); }

回答(2):

经典排序之冒泡排序