数据结构强势练习(链式结构的建立与增加结点)

本次介绍的是在数据结构链式结构的相关内容
本次利用c语言来实现相关的链式的操作,本次的案例中利用链式结构实现了增添数据元素并利用
循环实现链表中各个元素的输出。

#include<stdio.h>

typedef struct node{
int num;
struct node * next;
}node;

node node1={1,NULL};

int main(){
node *t_head=NULL;
node node2={2,NULL};
node node3={3,NULL};
node node5={5,NULL};

t_head=&node1;
node1.next=&node2;
node2.next=&node3;

node *t_tmp=NULL;
if(t_head){
t_tmp=t_head;
while(t_tmp->next){
t_tmp=t_tmp->next;
}
t_tmp->next=&node5;
}else{
t_head=&node5;
}

//显示所有的结点
t_tmp=t_head;
while(t_tmp){
printf("%-3d",t_tmp->num);
t_tmp=t_tmp->next;
}
printf("/n");
return 0;
}
在本次的c语言代码中主要涉及链表的建立,如果想要在线运行的话推荐使用工具代码在线工具
附上链接https://tool.lu/coderunner/

输出的结果为:
在这里插入图片描述
结点的定义:

typedef struct node{
int num;
struct node *node;
}node;

把一个结点实例化:
node node1={1,NULL};

定义一个头指针:
node *t_head=NULL;//这块我也不是很清楚,有点不理解

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值