·双循环链表,顾名思义,就是讲双链表和循环链表结合起来而成的,因此兼有两者的优势,并且劣势互补,具体请看前面的文章。
节点结构:
链表结构:
头文件:DCList.h
#ifndef _DCLIST_H
#define _DCLIST_H
#include<iostream>
#include<assert.h>
using namespace std;
typedef int ElemType;
typedef struct Node
{
ElemType data;
struct Node *next;
struct Node *prev;
}Node;
typedef struct List
{
Node *first;
Node *last;
size_t size;
}List;
void InitList(List *list);
void push_back(List *list, ElemType x);
void push_front(List *list, ElemType x);
void show_list(List *list);
Node* find(List *list, ElemType key);
bool delete_val(List *list, ElemType key);
bool insert_val(List *list, ElemType x);
bool resver(List *list);
bool pop_back(List *list);
bool pop_front(List *list);
ElemType getvalue(List *list,ElemType key);
bool modify(List *list,ElemType key,ElemType nkey);
bool clear(List *list);
bool destory(List *list);
bool sort(List *list);
size_t length(List *list);
Node *next(List *list,ElemType key);
Node *prio(List *list,ElemType key);
#endif
函数实现:DCList.cpp
#include"DCList.h"
void InitList(List *list)
{
Node *s = (Node *)malloc(sizeof(Node));
assert(s != NULL);
list->first = list->last = s;
list->first->prev = list->las