实现基于C/C++的数据结构的双向链表,此程序未经过严格实验,只是提供大概思路
#include<stdio.h>
#include<stdlib.h>typedef int DataType;
typedef struct node
{
DataType data;
struct node *prior,*next;
}DNode,*DLinkList;
DLinkList create_DLinkList()
{
DLinkList h;
h=(DLinkList)malloc(sizeof(DNode));
if(h)
{
h->next=NULL;
h->prior=NULL;
}
return h;
}
int insert_DLinkList(DLinkList p,DLinkList s)//insert before p
{
if(!s)
{
printf("p is NULL");
return -1;
}
s->next=p;
s->prior=p->prior;
p->prior->next=s;
p->prior=s;
return 1;
}
int delete_DLinkList(DLinkList p)
{
p->next->prior=p->prior;
p->prior->next=p->next;
free(p);
}
int main()
{
return 0;
}