线性表
栈&队列
串
二叉树
持续更新中,尽请期待!!!
双向链表
#include <bits/stdc++.h>
using namespace std;
#define ElemType int
#define Status int
typedef struct DuLNode{
ElemType data;
struct DuLNode *prior;
struct DuLNode *next;
} DuLNode, *DuLinkList;
void Init_DuL(DuLinkList &L){
L = (DuLinkList)malloc(sizeof(DuLNode));
L->data = NULL;
L->next = L;
L->prior = L;
}
Status Length_DuL(DuLinkList &L){
DuLinkList p;
p = L->next;
int i = 0;
while (p->data != NULL)
{
p = p->next;
i++;
}
return i;
}
DuLinkList GetElemP_DuL(DuLinkList &L, int i){
DuLinkList p = L->next;
int j = 1;
while (p && j < i){
p = p->next;
++j;
}
if (!p || j > i || i > (Length_DuL(L) + 1)){
p = NULL;
}
if (i == Length_DuL(L) + 1){
p = L;
}
return p;
}
Status ListInsert_DuL(DuLinkList &L, int i, ElemType e)
{
DuLinkList p, s;
if (!(p = GetElemP_DuL(L, i)))
return 0;
if (!(s = (DuLinkList)malloc(sizeof(DuLNode))))
{
return 0;
}
s->data = e;
s->prior = p->prior;
p->prior->next = s;
s->next = p;
p->prior = s;
return 1;
}
Status ListDelete_DuL(DuLinkList &L, int i, ElemType &e)
{
DuLinkList p;
if (!(p = GetElemP_DuL(L, i)))
{
return 0;
}
e = p->data;
p->prior->next = p->next;
p->next->prior = p->prior;
free(p);
return 1;
}
void Destory_DuL(DuLinkList &L)
{
DuLinkList p, q;
p = L->next;
while (p->data != NULL)
{
q = p->next;
p->prior->next = p->next;
p->next->prior = p->prior;
free(p);
p = q;
}
free(L);
}