struct Lnode
{
char data;
Lnode *prior;
Lnode *next;
};
void CreateList(Lnode * &head,char a[],int n)//尾插法创建链表
{
Lnode *p,*s;
int i=0;
head=(Lnode *)malloc(sizeof(Lnode));
head->next=NULL;
head->prior=NULL;
s=head;
while(i<n)
{
p=(Lnode *)malloc(sizeof(Lnode));
p->data=a[i];
p->next=s->next;
p->prior=s;
s->next=p;
s=p;
i++;
}
}
int ListInsert(Lnode *&head,int i,char e)//插入列表
{
Lnode *p,*s;
int k=0;
p=head;
while(k<i-1&&p!=NULL)
{
k++;
p=p->next;
}
if(p==NULL)
return 0;
else
{
s=(Lnode *)malloc(sizeof(Lnode));
s->data=e;
s->next=p->next;
if(p->next!=NULL)p->prior=s;
s->prior=p;
p->next=s;
return 1;
}
}
int ListDelete(Lnode *&head,int i,char &e)//删除列表
{
Lnode *p=head,*s;
int k=0;
while(k<i-1&&p!=NULL)
{
j++;
p=p->next;
}
if(p==NULL)
return 0;
else
{
s=p->next;
if(s==NULL)
return 0;
e=s->data;
p->next=s->next;
if(p->next!=NULL)p->next->prior=p;
free(s);
return;
}
}