2.链表“加一项”和链表遍历

文章展示了如何在C语言中使用结构体创建链表,包括初始化节点、连接节点以及使用`printLink`函数遍历并打印链表的内容。此外,还提及了Unix/Linux下的`cp`指令和`vi`编辑器中的删除操作。
摘要由CSDN通过智能技术生成

cp指令复制整个demo               cp demo1 demo2

cp指令复制demo中的语句        复制 nyy   粘贴 p    

vi 模式下删除光标所在向下n行                  ndd

  1 #include<stdio.h>
  2 
  3 struct test
  4 {
  5    int data;
  6    struct test *next;
  7 };
  8 
  9 void printLink(struct test *head)
 10 {
 11   struct test *point = head;
 12   while(point !=NULL ){
 13       printf("%d ",point->data);
 14       point = point->next;
 15   }
 16   putchar('\n');
 17 }
 18 
 19 int main()
 20 { 
 21   
 22   struct test t1 ={1,NULL};
 23   struct test t2 ={2,NULL};
 24   struct test t3 ={3,NULL};
 25   struct test t4 ={4,NULL};
 26   struct test t5 ={5,NULL};
 27 
 28   t1.next =&t2;
 29   t2.next =&t3;
 30   t3.next =&t4;
 31   t4.next =&t5;
 32  // printf("%d %d %d\n",t1.data,t1.next->data,t1.next->next->data);
 33   printLink(&t1);
 34 
 35   return 0;
 36 }

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值