C语言-链表结构体使用
使用struct结构体构造node链表,在link中声明node head 和 node tail 来命名两个结构体的头和尾链表
这里介绍链表的初始化和链表的清除操作
/* 构造链表的结构体 */ #include <stdio.h> typedef struct node{ int val; struct node *p_next; } node; typedef struct { node head; node tail; } link //进行链表的初始化 void link_init(link *p_link) { //将头指针指向尾指针 p_link->head.p_next = &p_link->tail; //将尾指针对应的指针地址设置为0 p_link->tail.p_next = NULL; } //进行链表的删除操作 void link_deinit(link *p_link) { while (p_link->head.p_next != &p_link->tail) { node *p_first = p_link->head; node *p_mid = p_first->p_next; node *p_last = p_mid->p_next; free(p_mid); p_mid = NULL; } }
相关推荐
kka 2020-09-14
成长共勉 2020-05-19
ipqtjmqj 2020-05-19
zhaochen00 2020-10-13
Mars的自语 2020-09-27
koushr 2020-11-12
范范 2020-10-28
steeven 2020-09-18
qiangde 2020-09-13
聚沙成塔积水成渊 2020-08-16
earthhouge 2020-08-15
aanndd 2020-08-12
范范 2020-07-30
bluetears 2020-07-28
mingyunxiaohai 2020-07-19
horizonheart 2020-07-19
liushall 2020-07-18
bluetears 2020-07-05