#include<stdio.h>
#include<stdlib.h>
typedef struct DULNODE{
int data;
struct DULNODE *priou;
struct DULNODE *next;
}DULNODE,*Dulinklist;
Dulinklist creat(Dulinklist L)//创建
{int node;
Dulinklist p;
L=(Dulinklist)malloc(sizeof(DULNODE));
L->next=NULL;
L->priou=NULL;
printf("\nplease input the node(end with 0)");
scanf("%d",&node);
while(node!=0)
{p=(Dulinklist)malloc(sizeof(DULNODE));
p->data=node;
p->next=L->next;
L->next=p;
p->priou=L;
printf("\nplease input the node(end with 0):");
scanf("%d",&node);
}
return L;
}
Dulinklist insert(Dulinklist L,int i,int x)//插入函数
{int j;
Dulinklist p,s;
p=L;j=0;
while(p!=NULL&&j<i-1)
{p=p->next;
++j;}
if(!s=(Dulinklist)malloc(sizeof(DULNODE)))
printf("\nerror\n");
s->data=x;
p->next=s->next;
s->next=p->next;
s->next->priou=s->priou;
p->next=s;
}
return L;
}
Dulinklist delete(Dulinklist L,int i)
{int j,x;
Dulinklist *p;
p=L,j=0;
while(p->next!=NULL&&j<i)
{p=p->next;
++j;
}
x=p->data;
p->priou->next=p->next;
p->next->priou=p->priou;
printf("the delete value is %d",x);
free(p);
return L;
}
void display(Dulinklist L)//输出
{Dulinklist p;
p=L->next;
while(p!=NULL)
{printf("%d",p->data);
p=p->next;
printf("\n");
}
}
int mian()//主函数
{int i,x;
Dulinklist L;
L=creat(L);
display(L);
printf("\n please input the position you want to insert:");
scanf("%d",&i);
printf("\ninput the node you want to insert:");
scanf("%d",&x);
L=insert(L,i,x);
display(L);
printf("\nplease inout the node position you want to delete:");
scanf("%d",&i);
L=delete(L,i);
display(L);
}
很感谢,如果可以的话能帮我把逻辑错误也该下吗?
等你有空时。谢谢了
谢谢
不好意思,有些话没讲。
我编译时不通过,有一些很奇怪的问题,我“delete”函数明明已经声明了,编译时说我没声明,
我不知道自己错在哪里,编译器那个有些看不懂,麻烦各位了。