#ifndef _LINKLIST_H_
#define _LINKLIST_H_
#include <stdio.h>
/* Enumerated data types */
typedef enum { AD_NOT_NEED_LOCK, AD_NEED_LOCK } AD_LOCK;
typedef enum { AD_ERROR, AD_OK } AD_STATUS;
typedef enum { AD_FALSE, AD_TRUE } AD_BOOLEAN;
typedef enum { AD_EQUAL, AD_LESS_THAN = -1, AD_GREATER_THAN = 1 } AD_RELATION;
typedef enum { AD_PRE_ORDER, AD_IN_ORDER, AD_POST_ORDER, AD_LEVEL_ORDER, AD_OUT_ORDER } AD_TRAVERSE_ORDER;
/* Data Structures */
typedef struct _LINKLIST LINKLIST; /* linklist (circular singly-linklist) */
#define LINKLIST_SIZE sizeof(LINKLIST)
typedef LINKLIST DEQUE; /* deque */
typedef DEQUE STACK; /* stack */
typedef DEQUE QUEUE; /* queue */
typedef struct _BTNODE BTNODE; /* binary tree node */
typedef struct _BTREE BTREE; /* binary Search Tree */
/* Pointers to function */
typedef AD_BOOLEAN (AD_EQUAL_FUNC) (void *, void *);
typedef AD_RELATION (AD_COMPARE_FUNC) (void *, void *);
typedef unsigned long (AD_HASH_FUNC) (const void *);
typedef AD_BOOLEAN (AD_TRAV_FUNC) (void *, void *);
/* Linklist Function Prototypes */
extern LINKLIST *ll_init(void);
extern AD_BOOLEAN ll_empty(LINKLIST *list);
extern LINKLIST *ll_prepend(LINKLIST *list, void *newdata);
extern LINKLIST *ll_append(LINKLIST *list, void *newdata);
extern int ll_swapline(LINKLIST *list, void *key1, void *key2, AD_LOCK lock_f, AD_COMPARE_FUNC *match);
extern void *ll_find(LINKLIST *list, void *key, AD_LOCK lock_f, AD_COMPARE_FUNC *match);
extern void *ll_delete(LINKLIST *list, void *key, AD_COMPARE_FUNC *match);
extern void *ll_get(LINKLIST *list, void **node, AD_LOCK lock_f);
extern AD_BOOLEAN ll_traverse(LINKLIST *list, AD_LOCK lock_f, AD_TRAV_FUNC *travFunc, void *param);
extern void ll_free(LINKLIST *list);
extern void *ll_tail(LINKLIST *list);
extern unsigned ll_count(LINKLIST *list);
extern void *ll_head(LINKLIST *list);
#define ll_insert ll_prepend
#define ll_add ll_append
/* Binary Search Tree function prototypes */
extern BTREE *bt_init(AD_COMPARE_FUNC *compFunc);
extern BTREE *bt_add(BTREE *bt, void *newitem);
extern void *bt_find(BTREE *bt, void *key, AD_LOCK lock_f);
extern void *bt_traverse(BTREE *bt, AD_LOCK lock_f, AD_TRAVERSE_ORDER order, AD_TRAV_FUNC *travFunc, void *param);
extern AD_BOOLEAN bt_empty(BTREE *bt);
extern unsigned bt_count(BTREE *bt);
extern unsigned bt_height(BTREE *bt);
void *bt_delete(BTREE *bt, void *key);
extern void bt_free(BTREE *bt);
extern void *bt_right(BTREE *bt);
extern void *bt_left(BTREE *bt);
//#define bt_left(node) ((node)->left)
//#define bt_right(node) ((node)->right)
//#define bt_data(node) ((node)->data)
/* Deque */
#define dq_init ll_init
#define dq_empty ll_empty
#define dq_push ll_prepend
#define dq_append ll_append
#define dq_free ll_free
#define dq_count ll_count
extern void *dq_pop (DEQUE *dq);
extern void *dq_eject (DEQUE *dq);
extern void *dq_top (DEQUE *dq);
extern void *dq_bottom (DEQUE *dq);
/* Stack */
#define s_init dq_init
#define s_empty dq_empty
#define s_push dq_push
#define s_add dq_push
#define s_free dq_free
#define s_top dq_top
#define s_pop dq_pop
#define s_count dq_count
/* Queue */
#define q_init dq_init
#define q_empty dq_empty
#define q_add dq_append
#define q_append dq_append
#define q_remove dq_pop
#define q_delete dq_pop
#define q_free dq_free
#define q_count dq_count
#endif
linklist.h
訂閱:
文章 (Atom)
沒有留言:
張貼留言