首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

如何将单链表改变成一个单循环聊表

2012-05-21 
怎么将单链表改变成一个单循环聊表/////////////////////////////////////////////////#includestdio.h#

怎么将单链表改变成一个单循环聊表
/////////////////////////////////////////////////
#include<stdio.h>
#include<stdlib.h>
typedef struct node 
{
int data;
struct node *next;
}lnode,*link;
//////////////////////////////////////////////////
link wei()
{
link l,p,r;//
int x;//
l=(lnode*)malloc(sizeof(lnode*));//
l->next=NULL;//
r=l;//
printf("请为节点赋值:\n");//
  scanf("%d",&x);//
while(x!=555)//
{
p=(lnode*)malloc(sizeof(lnode*));//
p->data=x;//
p->next=r->next;//
r->next=p;//
r=p;//
scanf("%d",&x);//
while(x< p->data)//
{ printf("错误,请重新输入\n");//
  scanf("%d",&x);//
}

}
return l;//
}
//////////////////////////////////////////////////

void shan(link l)
{
link p,pre;
pre=l;
p=l->next;
while(p!=NULL &&pre->data!=p->data)
{
  pre=p;
  p=p->next;
}
if(pre->data==p->data)
{
  pre->next=p->next;
}
else
{
printf("没有相同的\n");
}
}
//////////////////////////////////////////////////////
  void print(link l)
  {
link p;
  p=l->next;
printf("删除后的结果是:\n");
while(p!=NULL)
{
printf("%4d",p->data);
p=p->next;
}
  }
  //////////////////////////////////////////////////////
  void main()
{
link l;
l=wei();
  shan(l);
  print(l);


}
////////////////////////////////////////////////////////

请告诉我怎么样改,并在我原来的基础上写上改后的代码,谢谢

[解决办法]
核心代码应该是这样的,楼主对比下:

C/C++ code
void loopLink(Link *root){    if(root == 0) return;    Link *head = root;    while(head->next) head = head->next;    head->next = root;} 

热点排行