求助
2011-03-16 22:33
183 查看
我是一名c++初学者,这学期学习数据结构,有一个上机题是创建两个链表,并合并为一个,我创建的时候默认为升序排列。虽然编译通过了,但是无法运行处结果,求好心的高手帮忙指点迷津,在下感激不尽。下面是我的源程序。
#include<iostream>
using namespace std;
struct NodeTp{int data;struct NodeTp * next;};
NodeTp * Create()
{int x;
NodeTp * h=new NodeTp;
NodeTp * p;
NodeTp * last=h;
while(1)
{
cin>>x;
if(x==0)break;
p=new NodeTp;
p->data=x;
last->next=p;
last=p;
}
last->next=NULL;
p=h->next;
while(p)
{cout<<p->data<<endl;
p=p->next;
}
return h;
}
void main()
{NodeTp * La;
NodeTp * Lb;
NodeTp * Lc,*last,*p;
Lc=new NodeTp;
last=Lc;
La=Create();
Lb=Create();
while(1)
{if(La->data==0||Lb->data==0)break;
p=new NodeTp;
if(La->data<Lb->data)
{p->data=La->data;
La=La->next;
last->next=p;
last=p;}
else
{p->data=Lb->data;Lb=Lb->next;
last->next=p;
last=p;}
}
while(La)
{p=new NodeTp;
p->data=La->data;
last->next=p;
last=p;
La=La->next;
}
while(Lb)
{p=new NodeTp;
p->data=Lb->data;
last->next=p;
last=p;
Lb=Lb->next;
}
p->next=NULL;
cout<<Lc->data<<endl;
}
#include<iostream>
using namespace std;
struct NodeTp{int data;struct NodeTp * next;};
NodeTp * Create()
{int x;
NodeTp * h=new NodeTp;
NodeTp * p;
NodeTp * last=h;
while(1)
{
cin>>x;
if(x==0)break;
p=new NodeTp;
p->data=x;
last->next=p;
last=p;
}
last->next=NULL;
p=h->next;
while(p)
{cout<<p->data<<endl;
p=p->next;
}
return h;
}
void main()
{NodeTp * La;
NodeTp * Lb;
NodeTp * Lc,*last,*p;
Lc=new NodeTp;
last=Lc;
La=Create();
Lb=Create();
while(1)
{if(La->data==0||Lb->data==0)break;
p=new NodeTp;
if(La->data<Lb->data)
{p->data=La->data;
La=La->next;
last->next=p;
last=p;}
else
{p->data=Lb->data;Lb=Lb->next;
last->next=p;
last=p;}
}
while(La)
{p=new NodeTp;
p->data=La->data;
last->next=p;
last=p;
La=La->next;
}
while(Lb)
{p=new NodeTp;
p->data=Lb->data;
last->next=p;
last=p;
Lb=Lb->next;
}
p->next=NULL;
cout<<Lc->data<<endl;
}
相关文章推荐
- [求助].NET的Web服务引入不认识Array类型?
- 有谁调试成功过NiceErp (Delphi) 的源代码呀?求助,重谢!
- 求助java小问题
- 求助:有关SQLite在嵌入式设备上的调试问题
- [求助]我怎么就是不能单步调试我的C++程序?
- 求助:怎么样用VB实现对网页表格的自动填写功能?
- 下载求助
- 求助:blog无法发表文章
- 【求助】关于asp.net中的'Thread was being aborted'异常
- 求助啊,打开资源管理器的快捷键没用了
- 求助一条SQL语句
- 紧急求助,暂放主页,如有不妥,请移除
- 紧急求助:Captivate发布后没有声音
- 求助:如何修改和扩展WSS 3.0建立的站点
- D-Day +7 of .NET 第一次写简历,Virgin简历给了AMT;还有我的计算器啊!在CSDN的社区,向阿立求助了,仍旧无语。。。
- 有一道十分简单的数学题,但是我就是没想出来,不得以发在首页求助
- [求助]是"熊猫烧香"和"落雪"的综合体病毒,还是另有它因?
- 求助serialPort1 com1 port
- 求助!备份日志通过RSS导入失败,望指教!
- 求助!!!急需2.0版本OA数据库文件~~~