标题:[讨论]线性链表调用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



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-149668-1-1.html




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

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