List MakeEmpty()
{
List head =malloc(MAXSIZE*sizeof(struct LNode));
head->Last = 0;
return head;
}
Position Find( List L, ElementType X )
{
int i = 0;
for(i = 0;i < L->Last;i++)
{
if(L->Data[i] == X)
return i;
}
return ERROR;
}
bool Insert( List L, ElementType X, Position P )
{
if(L->Last>=MAXSIZE)
{
printf("FULL");return false;
}
else if(P < 0||P>L->Last)
{
printf("ILLEGAL POSITION");
return false;
}
int i;
for(i = L->Last;i>P;i--)
{
L->Data[i] = L->Data[i-1];
}
L->Data[P] = X;
// for(i = 0 ;i<MAXSIZE;i++)
// printf("%d ",L->Data[i]);
//
// printf("\n");
//
L->Last++;
return true;
}
bool Delete( List L, Position P )
{
if(P>=L->Last||P < 0)
{
printf("POSITION %d EMPTY",P);
return false;
}
int i = 0;
for(i = P;i<L->Last-1;i++)
{
L->Data[i] = L->Data[i+1];
}
L->Data[L->Last-1] = 0;
// for(i = 0;i<MAXSIZE;i++)
// printf("%d ",L->Data[i]);
// printf("\n");
L->Last--;
return true;
}