#include<iostream>
using namespace std;
#define OK 1;
#define ERROR 0;
typedef int Status;
typedef struct
{
int x;
int y;
}ElemType;
typedef struct LNode
{
ElemType data;
struct LNode *next;
}LNode,*LinkList;
//创建空链表 1
Status InitList(LinkList &L)
{
L=new LNode;
L->next=NULL;
return OK;
}
//头插法 2
Status Create_H(LinkList &L,int n)
{
int i=0;
while(i<n)
{
LinkList p =new LNode;
cin >> p->data.x >> p->data.y;
p->next=L->next;
L->next=p;
i++;
}
}
//尾插法 3
Status Create_T(LinkList &L,int n)
{
int i=0;
LinkList r,p;
r=L;
while(r->next)
{
r=r->next;
}
while(i<n)
{
p=new LNode;
cin >> p->data.x >> p->data.y;
r->next=p;
r=p;
i++;
}
r->next=NULL;
}
//遍历输出 4
Status outList(LinkList L)
{
LinkList p=L->next;
while(p)
{
cout << p->data.x << " " <<p->data.y << endl;
p=p->next;
}
return OK;
}
//获取i位置元素 5
Status GetList(LinkList L,int w,ElemType &e)
{
LinkList p=L->next;
int j=1;
while(p && j<w)
{
p=p->next;
j++;
}
e=p->data;
}
//获取元素i位置 6
ElemType LocateList(LinkList L,ElemType e)
{
LinkList p=L->next;
int i=1;
while(p)
{
if((p->data.x==e.x) &&(p->data.y==e.y))
{
return e;
}
p=p->next;
i++;
}
}
//插入 7
Status InsertList(LinkList &L,int w ,ElemType e)
{
LinkList p=L;
int i=0;
while (p&&i<w-1)
{
p=p->next;
i++;
}
LinkList S=new LNode;
S->data=e;
S->next =p->next;
p->next=S;
return OK;
}
//删除 8
Status DeleteList(LinkList &L,int w)
{
LinkList p=L->next;
int i=1;
while(p&&i<w-1)
{
p=p->next;
i++;
}
LinkList s=p->next;
p->next=s->next;
delete s;
return OK;
}
int main()
{
LinkList L;
InitList(L); //1
int N;
cin>>N;
while(N--)
{
char op;
cin>>op;
switch (op)
{
case 'H':
cout << "n input";
int n;
cin >> n;
Create_H(L,n);
break; //2
case'T':
cout << "input n";
cin >> n;
Create_T(L,n);//3
break;
case'G':
int w;
cout <<"GetList input w";
cin >> w;
ElemType e;
GetList(L,w,e);
cout << e.x <<" " << e.y << endl;//5
// outList(L);
break;
case'L':
cout <<"LocateList input e.x,e.y";
cin >> e.x>>e.y;
cout<<LocateList( L, e).x<<LocateList(L,e).y;//6
// outList(L);
break;
case'I':
cout <<"InsertList input w"<<endl;
cout <<"input e.x,e.y";
cin >> w;
cin >> e.x >> e.y;
InsertList(L, w , e);//7
// outList(L);
break;
case'D':
cout <<"Delete input w";
cin >>w;
DeleteList(L,w);
break;
}
}
outList(L);
return 0;
}