| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 741 人关注过本帖
标题:请教合并链表的程序问题
取消只看楼主 加入收藏
lw8484654
Rank: 1
等 级:新手上路
帖 子:223
专家分:0
注 册:2005-12-1
收藏
 问题点数:0 回复次数:1 
请教合并链表的程序问题

#include<iostream>
using namespace std;

class Element
{
public:
int number;
Element *point;
};

Element *Init()
{
Element *curret,*first;
first=curret=new Element;
int count=0;
while(count<4)
{
cout<<"输入数据:";
cin>>curret->number;
curret=curret->point=new Element;
count++;
}
curret->point=NULL;
return first;
}

void print(Element *p)
{
Element *curret;
curret=p;
cout<<"\n全部的数据是:";
while(curret->point!=NULL)
{
cout<<curret->number<<" ";
curret=curret->point;
}
cout<<endl;
}

void function(Element *a,Element *b)
{
Element *Acurret,*Bcurret,*c,*temp,*lc;
Acurret=a->point;
Bcurret=b->point;
lc=c=a;
lc->point=NULL;
while(Acurret->point!=NULL && Bcurret->point!=NULL)
{
if(Acurret->number<Bcurret->number)
{
temp=Acurret->point;
Acurret->point=lc->point;
lc->point=Acurret;
Acurret=temp;
}
else
{
temp=Bcurret->point;
Bcurret->point=lc->point;
lc->point=Bcurret;
Bcurret=temp;
}
}
while(Bcurret->point!=NULL)
{
temp=Bcurret->point;
Bcurret->point=lc->point;
lc->point=Bcurret;
Bcurret=temp;
}
print(c->point);
}

void main()
{
Element *PA,*PB,*Ahead,*Bhead;
Bhead=Ahead=new Element();
PA=Init();
Ahead->point=PA;
cout<<"\nA链表输入完毕!\n\n";
PB=Init();
Bhead->point=PB;
cout<<"\nB链表输入完毕!\n";
print(PA);
print(PB);
function(Ahead,Bhead);
}
各位大哥大姐帮我看看这个程序错在哪里呢?谢谢!!!

搜索更多相关主题的帖子: 链表 Element curret count 
2006-10-13 20:47
lw8484654
Rank: 1
等 级:新手上路
帖 子:223
专家分:0
注 册:2005-12-1
收藏
得分:0 
题目要求利用原表,不能生成新表!!!
2006-10-14 20:25
快速回复:请教合并链表的程序问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.025470 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved