易截截图软件、单文件、免安装、纯绿色、仅160KB

(转)一个简单的带头尾指针单向链表(C实现)

用C写了一个带头尾指针的单向链表,仅在尾部进行插入操作,在任意位置进行删除操作。因为只用到这么些功能,又因为懒,所以没有扩展。因为插入是固定在尾部进行,带一个尾指针的好处是显而易见的。当然删除时要付出一些开销。
  list.h
  -------------------------------------------
  /* list.h
  ** Copyright 2004 Coon Xu.
  ** Author: Coon Xu
  ** Date: 06 Sep 2004
  */
  #ifndef LIST_H
  #define LIST_H
  #include <stdio.h>
  #include <stdlib.h>
  struct listnode
  {
   struct listnode* next;
   int data;
  };
  struct list
  {
   struct listnode* head;
   struct listnode* tail;
   int count;
  };
  void list_init(struct list*);
  void list_insert(struct list*, struct listnode*);
  int list_delete(struct list*, struct listnode*);
  #endif
  ------------------------------------------
  list.c
  ------------------------------------------
  /* list.c
  ** Copyright 2004 Coon Xu.
  ** Author: Coon Xu
  ** Date: 06 Sep 2004
  */
  #include "list.h"
  void list_init(struct list* myroot)
  {
   myroot->count = 0;
   myroot->head = NULL;
   myroot->tail = NULL;
  }
  void list_insert(struct list* myroot, struct listnode* mylistnode)
  {
   myroot->count++;
  
   mylistnode->next = NULL;
   if(myroot->head == NULL)
   {
   myroot->head = mylistnode;
   myroot->tail = mylistnode;
   }
   else
   {
   myroot->tail->next = mylistnode;
   myroot->tail = mylistnode;
   }
  }
  int list_delete(struct list* myroot, struct listnode* mylistnode)
  {
   struct listnode* p_listnode = myroot->head;
   struct listnode* pre_listnode;
  
   //myroot is empty
   if(p_listnode == NULL)
   {
   return 0;
   }
  
   if(p_listnode =


相关文档:

C/C++中空指针与0与NULL和其他若干问题小结

什么是空指针常量(null pointer constant)?
[6.3.2.3-3] An integer constant expression with the value 0, or such an expression cast to type void *, is called a null pointer constant.
这里告诉我们:0、0L、'\0'、3 - 3、0 * 17 (它们都是“integer constant expression”)以及 (void*)0 等都是空 ......

由atof发现的C中浮点小数不精确问题


比如 输入1.9会显示1.899999 类似的问题
 
由于C语言中对于浮点小数的表达方式的局限导致的。C语言中10进制小数是直接用2进制小数来表示的。由于某些10进制小数根本无法用2进制小数来精确表达,譬如0.1,导致计算机不得不用近似的相差很小的2进制小数来表示这些10进制小数。   
  既然是近似,就一 ......

在C#里创建和使用C风格数据结构

在C#里创建和使用C风格数据结构,即非托管的数据结构,可以提高性能。
1 数据结构的定义
看下面例子:
    unsafe struct A {
        public int x;
    }
    unsafe struct B {
        pu ......

简述C和C++程序员学习历程

总是被同学们问到,如何学习C和C++才不茫然,才不是乱学,想了一下,这里给出一个总的回复。
  一家之言,欢迎拍砖哈。
  1、可以考虑先学习C.
  大多数时候,我们学习语言的目的,不是为了成为一个语言专家,而是希望成为一个解决问题的专家。做一个有用的程序员,做一个赚钱的程序员。我们的价值,将体现在客 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号