/*相较于6-5并无本质区别,两题要点都是一样的,选做一题即可*/
List MakeEmpty()
{
List L=(List)malloc(sizeof(struct LNode));
L->Next=NULL;
return L;
}
Position Find( List L, ElementType X )
{
while(L&&L->Next)
{
if(L->Data==X) return L;
L=L->Next;
}
if(L->Data==X) return L;
return ERROR;
}
bool Insert( List L, ElementType X, Position P )
{
List p=(List)malloc(sizeof(struct LNode));
p->Data=X;
p->Next=NULL;
List pb=L;
if(L==P) {
p->Next=L;
L=p;
return true;
}
while(pb->Next!=P&&pb->Next!=NULL)
{
pb=pb->Next;
}
if(pb->Next==P){
p->Next=P;
pb->Next=p;
return true;
}
else
printf("Wrong Position for Insertion\n");
return false;
}
bool Delete( List L, Position P )
{
List pb=L;
if(L==NULL) {
printf("Wrong Position for Deletion\n");
return false;
}
if(L==P) {
L=L->Next;
return true;
}
while(pb->Next!=P&&pb->Next!=NULL){
pb=pb->Next;
}
if(pb->Next==P){
pb->Next=P->Next;
return true;
}
else
printf("Wrong Position for Deletion\n");
return false;
}
{
List L=(List)malloc(sizeof(struct LNode));
L->Next=NULL;
return L;
}
Position Find( List L, ElementType X )
{
while(L&&L->Next)
{
if(L->Data==X) return L;
L=L->Next;
}
if(L->Data==X) return L;
return ERROR;
}
bool Insert( List L, ElementType X, Position P )
{
List p=(List)malloc(sizeof(struct LNode));
p->Data=X;
p->Next=NULL;
List pb=L;
if(L==P) {
p->Next=L;
L=p;
return true;
}
while(pb->Next!=P&&pb->Next!=NULL)
{
pb=pb->Next;
}
if(pb->Next==P){
p->Next=P;
pb->Next=p;
return true;
}
else
printf("Wrong Position for Insertion\n");
return false;
}
bool Delete( List L, Position P )
{
List pb=L;
if(L==NULL) {
printf("Wrong Position for Deletion\n");
return false;
}
if(L==P) {
L=L->Next;
return true;
}
while(pb->Next!=P&&pb->Next!=NULL){
pb=pb->Next;
}
if(pb->Next==P){
pb->Next=P->Next;
return true;
}
else
printf("Wrong Position for Deletion\n");
return false;
}