链表概念
什么是链表——数据结构——数据存放的思想——集合
数组特点:元素地址连续,缺点:增删查改,增删困难,不灵活
链表地址不连续:链表解决了增删困难的问题
第一个指针为链表头,指向其他地址
#include<stdio.h>
struct Test
{
int data;
struct Test *next;
};
int main()
{
int i;
int array[]={1,2,3,4,5,6,7,8,9,10};
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};
t1.next=&t2;//t1=lianbiaotou
t2.next=&t3;
printf("use t1 to print three num\n");
printf("%d %d %d\n",t1.data,t1.next->data,t1.next->next->data);
return 0;
}