#include <iostream>
#include <malloc.h>
using namespace std;
typedef struct LNone{
int data;
struct LNone *next;
}LNone,*Listnext;
void InitList(Listnext &L){
L = new LNone;
L->next = NULL;
}
void CreaterList(Listnext &L){
int n;
Listnext p,r;
r=L;
cout << "请输入节点的个数" << endl;
cin >> n;
cout << "请输入" <<n<<"个数"<< endl;
while(n--){
p = new LNone;
cin >>p->data;
p->next = NULL;
r->next = p;
r = p;
}
}
int GetList(Listnext L,int e){
Listnext p;
int j = 1;
p = L->next;
while(p != NULL && p->data != e){
j++;
p = p->next;
}
if(p == NULL)return -1;
return j;
}
void DelList(Listnext &L,int j){
Listnext p,r;
p = L->next;
int i = 1;
while(p != NULL && i < j-1){
p = p->next;
i++;
}
r = p->next;
p->next = r->next;
}
void InterList(Listnext &L,int e,int t){
Listnext p,r;
p = L->next;int i = 1;
while(p != NULL && i<t-1){
p = p->next;
i++;
}
r = new LNone;
r->data = e;
r->next = p->next;
p->next = r;
}
void List(Listnext L){
Listnext p;
p = L->next;
while(p!=NULL){
cout << p->data<<' ';
p = p->next;
}
}
int main()
{
int e,t;
Listnext L;
InitList(L);
CreaterList(L);
List(L);
cout<<endl<< "请输入要删除的值" << endl;
cin >> e;
t=GetList(L,e);
DelList(L,t);
List(L);
cout<<endl<< "请输入要插入的值" << endl;
cin >> e;
cout<<endl<< "请输入要插入的位置" << endl;
cin >> t;
InterList(L,e,t);
List(L);
}