操作系统志愿军

奉献你的诀窍让我们一起分享.给出你的疑难让我们一起讨论.

78 成员168 主题192 回复0 张照片

菜鸟的问题!!

Y
ytbszl80
2001-01-08 11:25
昨天闲着没事想写个有关list的程序!!要实现输入一个随机链表,然后多他进行排序输出,可是排序的部分怎么都运行不正确,有请哪位高手看看!! 源代码如下: #include #include void main() {typedef struct node {int data; struct node *next;} Nodetype; Nodetype *head,*tail,*swap,*swap2,*pr; int num,i,input,flag=1; head=new Nodetype; head=NULL; tail=new Nodetype; swap2=new Nodetype; pr=new Nodetype; cout<<"please input the node number:"<>num; for (i=0;i < num;i++) {cout<<"please input the "<>input; swap=new Nodetype; if(head==NULL) {swap->data=input; head=swap; tail=head; } else {swap->data=input; tail->next=swap; tail=tail->next; } } swap2=head; for (i=0;idata<next; } getch(); pr=head; swap=head; swap2=head->next; while(swap2!=tail) {if(swap2->data < swap->data) {if(flag) {swap->next=swap2->next; swap2->next=swap; head=swap2; swap2=swap->next; flag=0; } else {pr=head; if(head->data > swap2->data) {swap->next=swap2->next;swap2->next=head;head=swap2;swap2=swap->next;} else {while(swap2->data > pr->next->data) pr=pr->next; swap->next=swap2->next;swap2->next=pr->next;pr->next=swap2;swap2=swap->next; } } } else {swap=swap2;swap2=swap2->next;} } pr=head; if(head->data > swap2->data) {swap->next=swap2->next;swap2->next=head;head=swap2;swap2=swap->next;} else {while(swap2->data > pr->next->data) pr=pr->next; swap->next=swap2->next;swap2->next=pr->next;pr->next=swap2;swap2=swap->next; } swap=head; while(swap!=tail) {cout<data<next;} cout<data; delete swap;delete pr;delete swap2;delete tail;delete head; } 谢谢!!
Y
ytbszl80
2001-01-16 18:41
各位大虾修改的程序如下: #include #include void main() {typedef struct node {int data; struct node *next;} Nodetype; Nodetype *head,*tail,*swap,*swap2,*pr; int num,i,input,flag=1; head=new Nodetype; head=NULL; tail=new Nodetype; swap2=new Nodetype; pr=new Nodetype; cout<<"please input the node number:"<>num; for (i=0;i < num;i++) {cout<<"please input the "<>input; swap=new Nodetype; if(head==NULL) {swap->data=input; head=swap; tail=head; } else {swap->data=input; tail->next=swap; tail=tail->next; } } swap2=head; for (i=0;idata<next; } getch(); pr=head; swap=head; swap2=head->next; while(swap2!=tail) {if(swap2->data < swap->data) {pr=head; if(head->data > swap2->data) {swap->next=swap2->next;swap2->next=head;head=swap2;swap2=swap->next;} else {while(swap2->data > pr->next->data) pr=pr->next; swap->next=swap2->next;swap2->next=pr->next;pr->next=swap2;swap2=swap->next; } } else {swap=swap2;swap2=swap2->next;} } swap=head; while(swap!=tail) {cout<data<next;} cout<data; delete swap;delete pr;delete swap2;delete tail;delete head; }
B
babyai
2001-01-17 03:47
很想回答,但是?????????
老兄:
你写程序从来不写注释吗?这样很难读的!我真的很想回答你的问题,但是,看的我头都大了,你能不能把注释写上,不是很费事,英文也可以啊!
Y
ytbszl80
2001-01-18 04:18
请看我的回应!!
请看我的回应!!
M
MaxPayne
2002-05-07 19:45
高水准答案!
我比你菜得多!以后大家多多讨论!!OK?
1 / 1

登录后回复。