怎么改,才能在该键表中删除指定序号的元素,再显示键表?
#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;
}