link node

// DATE:2006-11-20 BY:Snowhill
#include "iostream.h"
struct link
{
 int data;
 link *next;
};
//头插法建立链表,带头结点

link *hcreat()
{
link *p,*s;
int i;
cin>>i;
p=new link;
p->next=NULL;
while(i)
{
 s=new link;
 s->data=i;
 s->next=p->next;
 p->next=s;
 cin>>i;
}
return p;

}
//create the node list with rear
link *rcreat()
{
 link *s,*p,*r;
 int i;
 p=r=new link;//the p and r is head
 p->next=NULL;
 cout<<"thes adress of p->next is "<<p->next;
 cin>>i;
 while(i)
 {
  s=new link;
  s->data=i;
  r->next=s;
  r=s;
  cin>>i;
 }
 r->next=NULL;
 cout<<"thes adress of r->next is "<<p->next;
 return p;
}

//print the link node
void print(link *head)
{
 link *p;
 p=head->next;
 while(p->next!=NULL)
 {
  cout<<p->data<<"->";
  p=p->next;
 }
 cout<<p->data;
 cout<<endl;
}

 

void main()
{
    link *p;
    p=rcreat();
    print(p);
   
}

posted on 2006-12-03 09:07 snowhill 阅读(267) 评论(0)  编辑 收藏 引用 所属分类: data structure


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


<2024年5月>
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678

导航

公告

又一年...........

留言簿(3)

随笔分类(13)

文章分类(131)

文章档案(124)

c++

java

linux

oracle

常用软件

其他

网络配置

系统安全

音乐

搜索

最新评论

阅读排行榜