| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 560 人关注过本帖
标题:[讨论]线性链表调用Delete删除函数时出现错误
只看楼主 加入收藏
sjjg
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2007-6-23
收藏
 问题点数:0 回复次数:1 
[讨论]线性链表调用Delete删除函数时出现错误

#include<iostream.h>

struct L

{
int data;

L * next;

};


L * head;

L * create()

{
L * ps;

L * pend;

cout<<"please input a data:"<<endl;

ps=new L;

cin>>ps->data ;

pend=ps;


while (ps->data !=0)

{

if (head==0)

head=ps;

else

pend->next =ps;

pend=ps;

ps=new L;

cin>>ps->data ;


}

pend->next =0;

delete ps;

return head;
}

void show ( L * head)

{
cout<<"the list is:"<<endl;

while ( head)

{
cout<<head->data<<endl ;

head=head->next ;

}
}


void Delete ( L * head, int num)

{
L * p;

if (!head)
{
cout<<"list is null"<<endl;

}

if (head->data ==num)


{
p=head;

head=head->next ;

delete p;

cout<<" the num is delete "<<endl;

}

//else

for ( L * s=head; s->next ;s=s->next )

{
if (s->next->data =num)

s->next =p;

s->next =p->next ;

delete p;

cout<<"the num is delete:"<<endl;
}


cout<<"the num isnot find:"<<endl;
}

void main()

{

int num;

L * head=create();

show (head);

cout<<"please input a num what you want to delete:"<<endl;

cin>>num;

Delete (head,num);

搜索更多相关主题的帖子: 链表 Delete 线性 删除 
2007-06-23 11:08
herbert_1987
Rank: 5Rank: 5
等 级:贵宾
威 望:15
帖 子:1314
专家分:0
注 册:2007-5-13
收藏
得分:0 
用Debug 看看问题出在哪里.

人生重要的不是所站的位置,而是所朝的方向
2007-06-23 14:29
快速回复:[讨论]线性链表调用Delete删除函数时出现错误
数据加载中...
 
   



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

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