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

(爱问答)

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

//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){

相关标签:谢谢

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

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

热门标签:
excel 网盘 破解 word dll
最新更新:
微软重新评估新的Outlook的使用时机 联想推出搭载联发科Helio G80芯片组的Tab M9平板 英特尔创新大赛时间确定! 微软Edge浏览器在稳定渠道中推出Workspaces功能 英伟达RTX4060TiGPU推出MaxSun动漫主题! 谷歌地图为用户提供了街景服务! GameSir 在T4 Kaleid中推出了一款出色的控制器! 微软开始在Windows 11 中测试其画图应用程序的新深色模式! LG电子推出全球首款无线OLED电视 英伟达人工智能芯片崭露头角! Steam Deck可以玩什么游戏-Steam Deck价格限时优惠 雷蛇推出CobraPro鼠标 Kindle电子阅读器可以访问谷歌商店吗 Windows10如何加入组策略 window10图片查看器怎么没有了?