📄 cetc_slist.c
字号:
/**
* Copyright (c) 2008, USEE
* All rights reserved.
*
* filename: cetc_slist.c
* abstract: about single list implenments;
*
*
* current version: 1.0
* authors: bolidehi
* date: 2008-8-27
*
* history version
* version:
* authors:
* date:
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//#include "cetc_type.h"
#include "cetc_slist.h"
/**
* 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)
{
if(prev != NULL)
{
node->next = prev->next;
prev->next = node;
if(list->tail == prev)
list->tail = node;
}
else
{
node->next = list->head;
list->head = node;
if(!list->tail)
list->tail = node;
}
++ list->count;
}
/**
* 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)
{
tagSListNode *prev = NULL;
tagSListNode *cur = list->head;
for( ; cur; prev=cur,cur=cur->next)
{
if(cur == node)
{
if(prev)
prev->next = node->next;
else
list->head = list->head->next;
if(node==list->tail)
list->tail = prev;
--list->count;
break;
}
}
}
/**
* func: empty a list by the node;
* @list :the single list ;
*/
void cetc_empty_slist(tagSList *list, tagFunSListDo freedata)
{
tagSListNode *next;
for(; list->head; list->head=next)
{
next = list->head->next;
freedata(list->head->data);
free(list->head);
}
list->tail = NULL;
list->count = 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -