#include <iostream>
#include <stdlib.h>
#include <stdio.h>
using namespace std;
#define MAXSIZE 5
#define ERROR -1
typedef int ElementType;
typedef struct LNode {
ElementType *Data;
int Last; /* 保存线性表中最后一个元素所在的位置 */
int length;
}SqList;
bool MakeEmpty(SqList &L);
int Find( SqList L, ElementType X );
bool Insert( SqList &L, ElementType X, int P );
bool Delete( SqList &L, int P );
int main()
{
SqList L;
ElementType X;
int length;
int P,j;
int N;
if (MakeEmpty(L)==false) return 0;
cin>>N;
while ( N-- ) {
cin>>X;
if ( Insert(L, X, 0)==false )
cout<<" Insertion Error: "<<X<<" is not in."<<endl;
}
cin>>N;
while ( N-- ) {
cin>>X;
P = Find(L, X);
if ( P == ERROR )
cout<<"Finding Error: "<<X<<" is not in."<<endl;
else
cout<<X<<" is at position "<<P<<"."<<endl;
}
cin>>N;
while ( N-- ) {
cin>>P;
if ( Delete(L, P)==false )
cout<<" Deletion Error."<<endl;
if ( Insert(L, 0, P)==false )
cout<<" Insertion Error: 0 is not in."<<endl;
}
return 0;
}
bool MakeEmpty(SqList &L)
{
L.Data = (ElementType *)malloc(MAXSIZE*sizeof(ElementType));
if(L.Data == NULL) return false;
L.length=-1;
return true;
}
int Find( SqList L, ElementType X )
{
int i;
for(i=0;i<=L.length;i++)
if(L.Data[i]==X) return i;
return ERROR;
}
bool Insert( SqList &L, ElementType X, int P )
{
if(L.length+1==MAXSIZE)
{
cout<<"FULL";
return false;
}
int j;
if((P<0)||(P>L.length+1) )
{
cout<<"ILLEGAL POSITION";
return false;
}
if(P == 0) {
for(int i = L.length; i >= 0; i--) {
L.Data[i+1] = L.Data[i];
}
L.Data[0] = X;
L.length++;
return true;
}
if(P == L.length) {
L.Data[L.length+1] = X;
L.length++;
return true;
}
for(j=L.length;j>=P;j--)
L.Data[j+1]=L.Data[j];
L.Data[P]=X;
++L.length;
return true;
}
bool Delete( SqList &L, int P )
{
if((P<0)||(P>L.length)){
cout<<"POSITION "<<P<<" EMPTY";
return false;
}
for(int j=P;j<=L.length-1;j++)
L.Data[j]=L.Data[j+1];
--L.length;
return true;
}