9.3链表静态添加和动态遍历
指针存放别人的地址
#include<stdio.h>
struct Test
{
int data;
struct Test *next;
};
void printLink(struct Test *head)
{
struct Test *point;
point = head;
while(point != NULL){
printf("%d",point->data);
point = point->next;
}
putchar('\n');
}
int main()
{
int i;
int array[] = {1,2,3};
for(i = 0;i<sizeof(array)/sizeof(array[0]);i++ ){
printf("%d",array[i]);
}
putchar('\n');
struct Test t1 = {1,NULL};
struct Test t2 = {2,NULL};
struct Test t3 = {3,NULL};
struct Test t4 = {4,NULL};
t1.next = &t2;
t2.next = &t3;
t3.next = &t4;
printf("use t1 to print three num\n");
printLink(&t1);
return 0;
}
|