带头尾结点的双链表
头文件
#ifndef DLINKED_LIST_H__
#define DLINKED_LIST_H__
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
typedef int ETYPE;
typedef struct DNode{
ETYPE elem;
struct DNode *prev;
struct DNode *next;
}DNode;
typedef struct DLinkedList{
struct DNode *head;
struct DNode *tail;
}*DLinkedList;
#define DNODESIZE sizeof(struct DNode)
DLinkedList dlinked_list_create(void);
bool dlinked_list_empty(DLinkedList list);
size_t dlinked_list_size(DLinkedList list);
int dlinked_list_insert_front(DLinkedList list,size_t pos,ETYPE elem);
int dlinked_list_insert_back(DLinkedList list,size_t pos,ETYPE elem);
int dlinked_list_push_front(DLinkedList list,ETYPE elem);
int dlinked_list_push_back(DLinkedList list,ETYPE elem);
int dlinked_list_delete_front(DLinkedList list,size_t pos,ETYPE *pelem);
int dlinked_list_delete_back(DLinkedList list,size_t pos,ETYPE *pelem);
int dlinked_list_pop_front(DLinkedList list,ETYPE *pelem);
int dlinked_list_pop_back(DLinkedList list,ETYPE *pelem);
int dlinked_list_get_front(DLinkedList list,size_t pos,ETYPE *pelem);
int dlinked_list_get_back(DLinkedList list,size_t pos,ETYPE *pelem);
int dlinked_list_front(DLinkedList list,ETYPE *pelem);
int dlinked_list_back(DLinkedList list,ETYPE *pelem);
void dlinked_list_travel(DLinkedList list,bool reverse,void (*travel)(ETYPE));
void dlinked_list_clear(DLinkedList list);
void dlinked_list_destroy(DLinkedList list);
int dlinked_list_find(DLinkedList list,ETYPE key);
#endif
实现函数
#include "dlinkedlist.h"
DLinkedList dlinked_list_create(void){
DLinkedList list = malloc(