首页 ┆ 网站地图 ┆ 在线留言 ┆ 游戏资讯 ┆ 资源下载 ┆ 端午节祝福 ┆ 迅雷在线影视
设为首页
加入收藏
联系我们
高级搜索
您当前的位置: 主页>C/C++>C语言>用C语言实现一个简单实用的单向链表list
用C语言实现一个简单实用的单向链表list
来源: 发布时间:2007-11-20 发布人: 浏览: 人次   字体: [ ]  

/* Concatenates two lists into first list */
void 
list_concat(list_t 
*first, list_t *second)
{
    
if (first->head)
    {
        
if (second->head)
        {
            first
->tail->next = second->head;
            first
->tail = second->tail;
        }
    }
    
else
        
*first = *second;
    second
->head = second->tail = NULL;

    first
->size += second->size;
}

/* Allocates a new listnode_t from heap */
listnode_t
* 
list_node_create(
void* data)
{
    listnode_t    
*node = (listnode_t*)malloc (sizeof(listnode_t));
    node
->next = NULL;
    node
->data = data;
    
return node;
}

listnode_t
* 
list_key_create(
long key)
{
    listnode_t    
*node = (listnode_t*)malloc (sizeof(listnode_t));
    node
->next = NULL;
    node
->key = key;
    
return node;
}

/* Allocates a empty list_t from heap */
list_t
* 
list_create()
{
    list_t    
*list = (list_t*)malloc (sizeof(list_t));
    list
->size = 0;
    list
->head = list->tail = NULL;
    
return list;
}

/* Frees a empty list_t from heap */
void 
list_destroy(list_t 
*in_list, pfcb_list_node_free  pf)
{
    list_remove_all(in_list, pf);    
    free(in_list);
}

/* Gets count of nodes in the list */
size_t 
list_size(
const list_t* in_list)
{
    
return in_list->size;
}

/* Gets node by index 0-based. 0 is head */
listnode_t
* 
list_node_at(
const list_t* in_list, int index)
{
    
int  i=0;
    listnode_t    
*node = in_list->head;

    assert(index 
>=0 && index < (int)in_list->size);

    
while (i < index)
    {
        node 
= node->next;
        i
++;
    }

    
return node;
}

 

公共头文件:

 

/* unistd.h 
   2008-09-15 Last created by cheungmine.
   All rights reserved by cheungmine.
*/
#ifndef UNISTD_H__
#define UNISTD_H__

/* Standard C header files included */
#include 
<stdio.h>
#include 
<stdlib.h>
#include 
<string.h>
#include 
<assert.h>

/*============================================================================*/

typedef unsigned 
char uchar, byte, BYTE;

typedef unsigned 
short uint16, word_t, ushort;

typedef unsigned __int32 
uint, uint32, dword_t, size_t;

typedef unsigned 
long    ulong;

typedef __int16 int16;
typedef __int32 int32;
typedef __int64 int64, longlong;

typedef    
long    lresult;

typedef unsigned __int64 uint64, qword_t, ulonglong;

#ifndef BOOL
    typedef 
int     BOOL;
    
#define TRUE  1
    
#define FALSE 0
#endif

#ifndef RESULT
    
#define RESULT        lresult
    
#define _SUCCESS    0
    
#define _ERROR        -1
#endif

#ifndef IN
#define IN
#endif

#ifndef OUT
#define OUT
#endif

#ifndef INOUT
#define INOUT
#endif

#ifndef OPTIONAL
#define OPTIONAL
#endif

#define SIZE_BYTE    1
#define SIZE_ACHAR    1
#define SIZE_WCHAR    2
#define SIZE_SHORT    2
#define SIZE_INT    4
#define SIZE_LONG    4
#define SIZE_FLT    4
#define SIZE_DBL    8
#define SIZE_WORD    2
#define SIZE_DWORD    4
#define SIZE_QWORD    8
#define SIZE_LINT    8
#define SIZE_INT64    8
#define SIZE_UUID    16


/*============================================================================*/
#endif    /*UNISTD_H__*/

 

好了。是不是很简单啊。适合初学者学习,适合喜欢简单就是生活的人!



共2页: 上一页 [1] 2 下一页
相 关 文 章   发布商链接
·字母全排列快速算法C代码
·C语言的无符号数据类型int,short,byt...
·C语言宏定义使用技巧
·linux下的c语言的随机数算法代码
·Linux下实时定时器在C语言中的实现和...
·怎样用C语言得到一个进程的全路径
·实例讲解C语言OPEN函数语法及其应用
·不定参数在C语言中的应用实例
·C语言开发实现的虚拟桌面程序代码
·C语言高手总结的新手容易犯的错误
 §最新评论:(评论内容只代表网友观点,与本站立场无关!)
网名: 验证码:  【所有评论】【↑返回顶部
评 分: 12 345
评论内容:(不能超过500字,请自觉遵守互联网相关政策法规。[按 Ctrl+Enter 可直接提交]
注意:请勿在本站发布政治话题、色情及违反法律的内容。
IT知道网 声明:刊登此文章是为了传递更多信息,文章内容仅供参考,转载请注明出处。
推 荐 文 章
·C语言高手总结的新手容易犯的
·C语言开发实现的虚拟桌面程序
·不定参数在C语言中的应用实例
·实例讲解C语言OPEN函数语法及
·怎样用C语言得到一个进程的全
·Linux下实时定时器在C语言中...
·linux下的c语言的随机数算法...
·C语言宏定义使用技巧
·C语言的无符号数据类型int,sh...
·字母全排列快速算法C代码
·如何用C语言编写Windows服务...
·C语言程序设计基础之预处理
热 门 文 章
·Linux下实时定时器在C语言中...
·C语言的无符号数据类型int,sh...
·C语言宏定义使用技巧
·C语言获得整数类型和浮点类型...
·Win32平台下如何安装Openssl...
·实例讲解C语言OPEN函数语法及...
·字母全排列快速算法C代码
·C语言开发实现的虚拟桌面程序...
·linux下的c语言的随机数算法...
·C语言数组排序小结
·c语言操作符的优先级排列及其...
·如何用C语言编写Windows服务...
·不定参数在C语言中的应用实例
·怎样用C语言得到一个进程的全...
·C语言程序设计基础之预处理
网站首页 - 关于本站 - 加入收藏 - 网站地图 - 友情连接 - 在线留言 - 联系我们 - 返回顶部
Copyright © 2007 IT知道网.[冀ICP备07026896号]. All Rights Reserved .