链表的改值

在查找的基础上改对应的值

  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 linkOfSearch(struct test *head,int num,int new)
 20 {
 21   struct test *point = head;
 22   while(point != NULL){
 23       if(point->data == num){
 24            point->data=new;
 25            return 1;
 26            break;
 27       }else{
 28            point = point -> next;
 29       }
 30   }
 31   return 0;
 32 }
 33 
 34 int main()
 35 {
 36 
 37   struct test t1 ={1,NULL};
 38   struct test t2 ={2,NULL};
 39   struct test t3 ={3,NULL};
 40   struct test t4 ={4,NULL};
 41   struct test t5 ={5,NULL};
 42 
 43   t1.next =&t2;
 44   t2.next =&t3;
 45   t3.next =&t4;
 46   t4.next =&t5;
 47 
 48   printLink(&t1);
 49   linkOfSearch(&t1,5,6);
 50   printLink(&t1);
 51 
 52   return 0;
 53 }
 54 
    

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值