本文主要是介绍Linux--链表 第二十五天,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
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;
}
这篇关于Linux--链表 第二十五天的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!