在查找的基础上改对应的值
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