本次介绍的是在数据结构链式结构的相关内容
本次利用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;//这块我也不是很清楚,有点不理解