#includestdio.h//双向链表定义typedefstructnode{intdata;//数据域structnode*prior;//前驱structnode*next;//后继}dulnode,*dullinklist;//初始化dullinklistinitlist(){dullinklistl;l=(dullinklist)malloc(sizeof(dulnode));//生成新结点l-prior=0;l-next=0;printf(--初始化成功--\n);returnl;}//表长intlistlength(dullinklistl){dullinklistp;intcount=0;p=l-next;//printf(%d,p);while(p){p=p-next;count++;}returncount;//返回表长度}//后插法创建双向链表voidcreatelist(dullinklistl,intn){dullinklistp,r;inti=0;r=l;for(;in;i++){p=(dullinklist)malloc(sizeof(dulnode));//生成新结点printf(输入元素:);scanf(%d,&p-data);//输入元素p-next=0;r-next=p;p-prior=r;//插入新结点r=p;//尾结点后移}printf(--创建双向链表成功--\n);}//插入voidinsertlist(dullinklistl,inti,inte){intj=0;dullinklistp,q;p=l;while(p&&ji-1){p=p-next;//找寻第i-1个结点++j;}if(!p||ji-1){printf(插入失败\n);return;}q=(dullinklist)malloc(sizeof(dulnode));q-data=e;//在最后一位插入元素if(p-next==0){q-next=0;p-next=q;q-prior=p;printf(--插入成功--\n);return;}//在非最后一位插入元素q-next=p-next;p-next-prior=q;p-next=q;q-prior=p;printf(--插入成功--\n);}//删除intdellist(dullinklistl,inti,int*e){intj=0;dullinklistp,q;p=l;//找寻第i-1个结点while(p&&ji-1){p=p-next;j++;}if(!p||ji-1){printf(删除失败\n);return-1;}q=p-next;//被删除结点if(q-next)//删除元素非最后一位{p-next=q-next;q-next-prior=p;}elsep-next=0;//删除元素位于最后一位*e=q-data;free(q);printf(--删除成功--\n);return*e;}//打印表中元素voidprintlist(dullinklistl){dullinklistp;p=l-next;while(p){printf(%3d,p-data);p=p-next;}putchar('\n');}voidmain(){inti,e,n;dullinklistl;printf(====================================初始化====================================);putchar('\n');l=initlist();printf(表长:%d\n,listlength(l));printf(=================================创建双向链表=================================);putchar('\n');printf(元素个数:);scanf(%d,&n);createlist(l,n);printf(表长:%d\n,listlength(l));printf(======================================插入====================================);printf(\n插入位置:);scanf(%d,&i);printf(插入元素:);scanf(%d,&e);insertlist(l,i,e);printf(表长:%d\n,listlength(l));printlist(l);printf(======================================删除====================================);printf(\n删除位置:);scanf(%d,&i);dellist(l,i,&e);printf(表长:%d\n,listlength(l));printlist(l);//printf(e=%d\n,e);printf(被删除元素:%d\n,e);printf(======================================END====================================);putchar('\n');}