⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cetc_slist.h

📁 linux 数据结构堆栈操作。。 。。 。。 。
💻 H
字号:
/**
 * Copyright (c) 2008, USEE 
 * All rights reserved.
 *
 * filename: cetc_slist.h
 * abstract: about single list header;
 *			 
 *
 * current version: 1.0
 * authors: bolidehi
 * date: 2008-8-27
 *
 * history version
 * version: 
 * authors: 
 * date: 
 */
#ifndef _CETC_LIST_H_
#define _CETC_LIST_H_

/**
 * structure of list node;
 */
typedef struct _tagSListNode tagSListNode;
struct _tagSListNode
{
	void			*data;
	tagSListNode	* next;
};

/**
 * func:compare single list node 
 * @data1: first list data 
 * @data2: second list data;
 * $return: if(data1>data2) return 1 else if(data1<data2) return -1 else return 0; 
 */
typedef int (*tagFunComp)(void *data1, void *data2);

typedef void (*tagFunSListDo)(tagSListNode *node);

typedef struct _tagSList tagSList;
struct _tagSList
{
	int				count;
	tagSListNode	*head;
	tagSListNode	*tail;
};

#ifdef __cplusplus 
extern  "C" {
#endif

/**
 * func : init single list;
 * @list : the single list;
 */
static __inline void cetc_init_slist(tagSList *list)
{
	memset(list, '\0', sizeof(tagSList));
}

/**
 * func  : insert a node into list;
 * @list : the single list;
 * @node : the node that want to be inserted into list;
 * @prev : inserted postion,indicate the inserted node 's previous;
 */
void cetc_insert_slist(tagSList *list, tagSListNode * node, tagSListNode *prev);

/**
 * func: add a node into list head;
 * @list: the single list;
 * @node: the node that to be added;
 */
static __inline void cetc_add_slist_head(tagSList *list, tagSListNode * node)
{
	cetc_insert_slist(list, node, NULL);
}

/**
 * func: add a node into  list tail;
 * @list : the single list ;
 * @node : the node that to be added;
 */
static __inline void cetc_add_slist_tail(tagSList *list, tagSListNode *node)
{
	cetc_insert_slist(list, node, list->tail);
}


/**
 * func: search a list by the node;
 * @list :the single list ;
 * @key  : search key;
 * @com  : function for comparing;
 * @return : return single list node; 
 */
static __inline tagSListNode *cetc_search_slist(tagSList* list, void *key, tagFunComp com)
{
	tagSListNode *node = list->head;
	for(; node && (com(key, node)!=0); node=node->next);
	return node;
}

/**
 * func: remove a list by the node;
 * @list :the single list ;
 * @node : the node that to be removed;
 */
void cetc_remove_slist_node(tagSList *list, tagSListNode *node);

/**
 * func: empty a list by the node;
 * @list :the single list ;
 */
void cetc_empty_slist(tagSList *list, tagFunSListDo freedata);

/**
 * func: for each node to do proc by the function;
 * @list :the single list
 * @func: call back function;
 */
static __inline void cetc_foreach_slist_do(tagSList *list, tagFunSListDo func)
{
	tagSListNode *curr = list->head;
	for(; curr; curr= curr->next)
	{
		func(curr);
	}
}

#ifdef __cplusplus 
}
#endif


#endif	

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -