bool InsertOFPos(SingleList *head,ElemType val,int pos)
{
if(head==NULL) exit(0);
if(pos<0) return false;
SingleList *p=head;
while(pos&&p!=NULL)
{
pos--;
p=p->next;
}
if(p==NULL)
return false;
SingleList *newNode=ApplyNode(val,p->next);
if(newNode==NULL)
return false;
p->next=newNode;
return true;
}
void Resever(SingleList *head)
{
if(head==NULL
||head->next==NULL
||head->next->next==NULL) exit(0);
SingleList *p=head->next;
SingleList *q=p->next;
head->next = NULL;
while (p!= NULL)
{
p->next=head->next;
head->next=p;
p=q;
if(q!=NULL)
{
q=q->next;
}
}
ShowList(head);
}
|