link.h
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include<stdlib.h>
#include<string.h>
#include<assert.h>
typedef int datatype;
typedef struct doubleLSTNODE {
datatype daa;
struct doubleLSTNODE* prev;
struct doubleLSTNODE* nest;
}LstNode;
LstNode*doublelinkinitfun();
void pushback(LstNode* p,datatype a);
void print(LstNode* p);
void pushfront(LstNode* p, datatype a);
void popback(LstNode* p);
void popfront(LstNode* p);
void referposinsert(LstNode* ps);
void referposdel(LstNode* ps);
test.c
#include"link.h"
int main()
{
LstNode* ps=doublelinkinitfun();
pushback(ps,1);
pushback(ps,2);
pushback(ps,3);
pushback(ps,4);
pushfront(ps, 5);
pushfront(ps, 6);
popback(ps);
popfront(ps);
print(ps);
system("pause");
return 0;
}
link.c
#include"link.h"
LstNode* doublelinkinitfun()
{
LstNode* ps = (LstNode*)malloc(sizeof(LstNode));
ps->nest = ps;
ps->prev = ps;
return ps;
}
void pushback(LstNode* p, datatype a)
{
LstNode* newnode = (LstNode*)malloc(sizeof(LstNode));
newnode->daa = a;
assert(p);
LstNode* tail = p->prev;
tail->nest = newnode;
newnode->prev = tail;
p->prev = newnode;
newnode->nest = p;
}
void print(LstNode* p)
{
assert(p);
LstNode* cur = p->nest;
while (cur!=p)
{
printf("%d ", cur->daa);
cur = cur->nest;
}
printf("\n");
}
void pushfront(LstNode* p, datatype a)
{
LstNode* newnode = (LstNode*)malloc(sizeof(LstNode));
newnode->daa = a;
assert(p);
LstNode* tmp = p->nest;
p->nest = newnode;
newnode->prev = p;
newnode->nest = tmp;
tmp->prev = newnode;
}
void popback(LstNode* p)
{
assert(p);
if (p->nest == p)
{
return;
}
else
{
LstNode* tmp1 = p->prev;
LstNode* tmp2 = tmp1->prev;
free(tmp1);
p->prev = tmp2;
tmp2->nest = p;
}
}
void popfront(LstNode* p)
{
assert(p);
if (p->nest == p)
{
return;
}
LstNode* tmp1;
LstNode* tmp2;
tmp1 = p->nest;
tmp2 = tmp1->nest;
free(tmp1);
p->nest = tmp2;
tmp2->prev = p;
}
void referposinsert(LstNode* ps)
{
LstNode* tmp1 = ps->prev;
LstNode* newnode = (LstNode*)malloc(sizeof(LstNode));
tmp1->nest = newnode;
newnode->prev = tmp1;
newnode->nest = ps;
ps->prev = newnode;
}
void referposdel(LstNode* ps)
{
LstNode* tmp1 = ps->nest;
LstNode* tmp2 = ps->prev;
free(ps);
ps == NULL;
tmp2->nest = tmp1;
tmp1->prev = tmp2;
}