标题:[求助]怎么改,才能在该键表中删除指定序号的元素,再显示键表?
取消只看楼主
autumnluo
Rank: 1
等 级:新手上路
帖 子:40
专家分:0
注 册:2005-12-7
 问题点数:0 回复次数:0 
[求助]怎么改,才能在该键表中删除指定序号的元素,再显示键表?

怎么改,才能在该键表中删除指定序号的元素,再显示键表?
#include<iostream.h>
struct node
{
int date;
node*next;
};
node*deleteData(int n,node*head);
void*outputList(node*);
int main()
{
int n;
int num;

node *listHead=NULL;
cout<<"plaese enter the number of nodes:";
cin>>n;
cout<<"pleaase enter"<<n<<"intebers:";
for(int i=0;i<n;i++)
{cin>>num;
}
outputList(listHead);

cin>>num;
cout<<"\nplease enter the number tobe deleted:";
cin>>n;
listHead=deleteData(num,listHead);
outputList(listHead);
return 0;
}
node*deleteData(int n,node *head)
{node*curNode=head;
node*preNode=NULL;

cin>>n;
for(int i=1;i<=n;i++)
{preNode=curNode;
curNode=curNode->next;
}preNode->next=curNode->next;
delete curNode;
cout<<"delete"<<n<<"from the list."<<endl;
return head;

//末找到n
cout<<"can't find"<<n<<"in the list."<<endl;
return head;
}

搜索更多相关主题的帖子: include number 元素 
2006-04-18 10:37



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




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

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