正在学链表,说说链表到底是怎么连接起来的???详细点,分全在这里了。
说说链表到底是怎么连接起来的???详细点,分全在这里了。
程序代码:
#include <stdio.h>
int main (void) {
//定义结构entry
struct entry {
int value; //整形数值
struct entry *next; //指向另一个entry结构的指针
};
struct entry n1,n2,n3; //定义3个结构变量
struct entry *list_pointer=&n1; //指定表头
//手动建立链表
n1.next=&n2; //将结构n1的指针指向n2
n2.next=&n3; //将结构n2的指针指向n3
n1.value=100;
n2.value=200;
n3.value=300;
n3.next=0; //指定表尾
//遍历链表
while(list_pointer!=(struct entry *)0) {
printf ("%i\n",list_pointer->value);
list_pointer=list_pointer->next;
}
return 0;
}
