1.
链表 t1.next -> data t1.next->next->data
'.'(点号)的优先级比->的大
所以 t1.next->data 就可以了 不用(t1.next)->data
2.
链表的静态增加和动态遍历
打印链表算法,
void printLink(struct Test *head)
{
struct Test *point;
point = head;
}
#include<stdio.h>
struct Test
{
int data;
struct Test *next;
};
void printLink(struct Test *head)
struct Test *point;
point = head;
printf("use Link to print num:\n");
while(point !=NULL){
printf("%d ",point->data);
point = point->next;
}
putchar('\n');
}
int main()
{
int i;
int arr[] = {1,2,3,4,5,6,7,8,9,10};
for(i =0 ;i<sizeof(arr)/sizeof(arr[0]);i++){
printf("%d ",arr[i]);
}
putchar('\n');
struct Test t1 = {1,NULL};
struct Test t2 = {2,NULL};
struct Test t3 = {3,NULL};
struct Test t4 = {4,NULL};
struct Test t5 = {5,NULL};
t1.next = &t2;
t2.next = &t3;
t3.next = &t4;
t4.next = &t5;
printf("use t1 to print three nums:\n");
printf("%d %d %d %d\n",t1.data,t1.next->data,t1.next->next->data,t1.next->next->next->data);
printLink(&t1);
return 0;
}