Position Find( List L, ElementType X )
{
Position p=L;
while(p!=NULL)
{
if(p->Data==X)
{
return p;
}
p=p->Next;
}
return ERROR;
}
List Insert( List L, ElementType X, Position P )
{
Position p=L,q;
if(P==L)
{
q=malloc(sizeof(struct LNode));
q->Data=X;
q->Next=L;
return q;
}
while(p!=NULL)
{
if(p->Next==P)
{
q=malloc(sizeof(struct LNode));
q->Data=X;
q->Next=p->Next;
p->Next=q;
return L;
}
p=p->Next;
}
printf("Wrong Position for Insertion\n");
return ERROR;
}
List Delete( List L, Position P )
{
Position p=L,q;
if(P==L)
{
q=L;
L=L->Next;
free(q);
return L;
}
while(p!=NULL)
{
if(p->Next==P)
{
p->Next=P->Next;
free(P);
return L;
}
p=p->Next;
}
printf("Wrong Position for Deletion\n");
return ERROR;
}