求助
来源:互联网 发布:淘宝宣传视频收费 编辑:程序博客网 时间:2024/05/29 17:21
我是一名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;
}
- 求助
- 求助
- 求助
- 求助
- 求助
- 求助
- 求助!!
- 求助!!
- 求助
- 求助
- 求助
- 求助
- 求助
- 求助
- 求助
- 求助
- 求助!!!!
- 求助~~
- 选修课:唐宋词课堂鉴赏笔记01
- 量筒量水问题1--一个盛满水的池子,有一个6升的量筒,一个5升的量筒,怎样量出3升水?
- linux自定义服务
- Metro of SH
- linux上开发minigui的配置过程
- 求助
- windowswriter的测试blog
- ArrayList和LinkedList的特点
- 关于#pragma +参数的使用说明y(转自百度百科)
- POJ 2739(连续素数和) 解题报告
- CodeSmith系列
- 数据的大小分类
- 密码库LibTomcrypt的内容介绍及分析
- yii(一)