#include<iostream.h>
struct node
{
int date;
node*next;
};
node*deleteData(int n,node*head);
void*outpputList(node*head);
int main()
{
int n;
int num;
node *listHead=NULL;
cout<<"plaese enter the number of nodes:";
cin>>n;
cout<<"pleaase enter"<<n<<"intebers:";
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;
}
void *outputList(node*head)
{
cout<<"list:";
node *curNode=head;
while(curNode)
{
cout<<curNode->data;
if(curNode->next)
cout<<"->";
curNode=curNode->next;
}
cout<<endl;
return;}