#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct list_node
{
int data ;
struct list_node *next ;
};
typedef struct list_node list_single ;
list_single *create_list_node(int data)
{
list_single *node = NULL ;
node = (list_single *)malloc(sizeof(list_single));
if(node == NULL){
printf("malloc fair!\n");
}
memset(node,0,sizeof(list_single));
node->data = data ;
node->next = NULL ;
return node ;
}
int main(void)
{
int data = 100 ;
int data2=200;
list_single *node_ptr = create_list_node(data); //创建一个节点
printf("node_ptr->data=%d\n",node_ptr->data); //打印节点里的数据
printf("node_ptr->next=%d\n",node_ptr->next);
node_ptr= node_ptr->next;
node_ptr=create_list_node(data2);
printf("node_ptr->data=%d\n",node_ptr->data); //打印节点里的数据
printf("node_ptr->next=%d\n",node_ptr->next);
free(node_ptr);
return 0 ;
}
C语言链表创建
最新推荐文章于 2022-10-21 23:21:58 发布