#include using namespace std;

#define OK 1 #define ERROR 0 #define OVERFLOW -2 typedef int Status; typedef int ElemType;

typedef struct DuLNode { ElemType data; struct DuLNode *prior; struct DuLNode *next; } DuLNode, *DuLinkList;

DuLNode *GetElemP_DuL(DuLinkList L, int i) { int j; DuLinkList p; p = L->next; j = 1; while (j < i && p) { p = p->next; ++j; } if (!p || j > i) return NULL; return p; }

Status ListDelete_DuL(DuLinkList &L, int i) { DuLinkList p; if (!(p = GetElemP_DuL(L, i))) return ERROR; p->prior->next = p->next; p->next->prior = p->prior; delete p;
return OK; }

void CreateDuList(DuLinkList &L,int n) //该函数未显示细节

void print(DuLinkList &L) { DuLinkList p; int flag=1; p = L->next; while (p) { if(flag) cout << p->data; else cout << ' ' << p->data; flag=0; p = p->next; } }

int main() { int a; ElemType e; int n; DuLinkList L, p;
cin >>n; CreateDuList(L,n); cin >> a; ListDelete_DuL(L, a); print(L); return 0; }

双向链表删除节点操作详解及代码实现

原文地址: http://www.cveoy.top/t/topic/jSCD 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录