首页 > 电脑

编写删除双向链表第i个结点的程序。求解,谢谢

更新时间2018-11-25 04:04:23

//CreateList_L.cpp//To create a LinkList#include <stdlib.h>#include <iostream.h>#include <conio.h># define TRUE 1# define FALSE 0# define OK 1# define ERROR 0# define INFEASIBLE -1# define OVERFLOW -2typedef struct DuLNode{ int data;struct DuLNode *prior;struct DuLNode *next;}DuLNode,*DuLinkList;// 初始条件:L已存在。操作结果:返回L中数据元素个数int ListLength(DuLinkList L){int i=0;DuLinkList p=L->next; // p指向第一个结点while(p!=L) // p没到表头{i++;p=p->next;}return i;}// 由双链循环线性表L的头结点出发,正序输出每个数据元素void ListTraverse(DuLinkList L){DuLinkList p=L->next;while(p!=L){cout<<p->data<<" ";p=p->next;}cout<<endl;}// 由双链循环线性表L的头结点出发,逆序输出每个数据元素void ListTraverseBack(DuLinkList L){DuLinkList p=L->prior;while(p!=L){cout<<p->data<<" ";p=p->prior;}cout<<endl;}//To Creatre a DuLinkList L with HeadNodevoid CreateList_DuL(DuLinkList &L){int n;int i;DuLNode *p;L=(DuLinkList)malloc(sizeof(DuLNode));L->next=L->prior=L;cout<<"CreateList_L"<<endl<<"================"<<endl;cout<<"Please input the Init DuLinkNode Number: <eg. 5> ";cin>>n;cout<<"Please input the data for DuLinkList Nodes: <eg. 34,67,3,-9,45,...>"<<endl;for(i=n;i>0;--i){p=(DuLinkList)malloc(sizeof(DuLNode));cin>>p->data; //Reverse order inputing for Creating a LinkListp->prior=L;p->next=L->next;L->next->prior=p;L->next=p;}if(n){cout<<endl;cout<<"Success to Create a DuLinkList !"<<endl;ListTraverse(L);cout<<endl;}else cout<<"A NULL DuLinkList have been created !"<<endl;}//ListInsert_Dul()int ListInsert_DuL(DuLinkList &L){DuLNode *p=L,*s;int j=0;int i;int e;cout<<"======"<<"before insert:"<<"======"<<endl;ListTraverse(L);cout<<"input the location you want to insert:";cin>>i;while (i<1||i>ListLength(L)+1){

相关标签:谢谢

上一篇:TypeError:Error#1010:术语尚未定义,并且无任何属性

下一篇:可以每一句详细解释一下这个代码吗,八皇后,我是大一学生,刚刚接触c++,望大神解答