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

📄 liblist.c

📁 linux 下通过802.1认证的安装包
💻 C
字号:
/**
 * A generic linked list library.
 *
 * Licensed under a dual GPL/BSD license.  (See LICENSE file for more info.)
 *
 * \file liblist.c
 *
 * \author chris@open1x.org
 *
 * $Id: liblist.c,v 1.1.2.5 2007/07/21 11:42:48 cgrohmann Exp $
 * $Date: 2007/07/21 11:42:48 $
 **/

#include <stdio.h>

#include "liblist.h"

/**
 * \brief Add a node to the head of the list.  If the list is empty, then it will be created.
 *
 * @param[in,out] addtolist   The list that we want to add a node to.
 * @param[in] newnode   The node that we want to add to the list.
 **/
void liblist_add_to_head(genlist **addtolist, genlist *newnode)
{
	newnode->next = (*addtolist);
	(*addtolist) = newnode;
}

/**
 * \brief Add a node to the end of the list.
 *
 * @param[in,out] addtolist   The list that we want to add a node to.
 * @param[in] newnode   The node that we want to add to the end of the list.
 **/
void liblist_add_to_tail(genlist **addtolist, genlist *newnode)
{
	genlist *cur = NULL;

	if ((*addtolist) == NULL)
	{
		(*addtolist) = newnode;
		return;
	}

	cur = (*addtolist);

	while (cur->next != NULL) cur = cur->next;

	cur->next = newnode;
}

/**
 * \brief Delete a child node.
 *
 * @param[in,out] parent   The parent node whose child we want to delete.
 * @param[in] delfunc   The function to call to properly delete the child node.
 **/
void liblist_delete_child_node(genlist *parent, node_delete_func delfunc)
{
	genlist *cur = NULL;

	if (parent->next == NULL) return;  // Do nothing.

	cur = parent->next->next;

	(*delfunc)(&parent->next);

	parent->next = cur;
}

/**
 * \brief Delete a list.
 *
 * @param[in,out] list   The list that we want to delete.
 * @param[in] delfunc   The function to call to properly delete each node in the list.
 **/
void liblist_delete_list(genlist **list, node_delete_func delfunc)
{
	genlist *cur = NULL, *next = NULL;

	cur = (*list);

	while (cur != NULL)
	{
		next = cur;
		cur = cur->next;

		(*delfunc)(&next);
	}

	(*list) = NULL;
}

⌨️ 快捷键说明

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