c语言学习笔记.链表.

链表:

  链表单个节点的数据结构。链表的实现主要依靠结构体和指针。

  头指针(head)指向链表的第一个节点,然后第一个节点中的指针指向下一个节点,然后依次指到最后一个节点,这样就构成了一条链表。

struct node
{
    int data;        //存储数据
    node *next;   //指针,指向下一个
};

单向链表:

创建节点:

 1 #include <stdio.h>  
 2 #include <stdlib.h>
 3 #include <string.h> 
 4 typedef struct  list_node  
 5 {  
 6     int data ;   
 7     struct list_node *next ;  
 8 }list_single;  
 9 
10 int main(void)  
11 {  
12     list_single *node = NULL ;          //1、首先,当然是定义一个头指针  
13     node = (list_single *)malloc(sizeof(list_single)); //2、然后分配内存空间  
14     if(node == NULL){  
15         printf("malloc fail!
");  
16     }  
17     memset(node,0,sizeof(list_single)); //3、清空  
18     node->data = 100 ;                   //4、给链表节点的数据赋值  
19     node->next = NULL ;                 //5、将链表的指针域指向空  
20     printf("%d
",node->data);  
21     free(node);                //释放内存
22 
23     return 0 ;  
24 }
原文地址:https://www.cnblogs.com/protogenoi/p/9013442.html