5. 链表
5.1 链表是由一连串节点组成的,其中每个节点都包含指向下一个节点的指针。struct node{
int value;
struct node *next;
};
5.2 添加链表节点
struct node *first = NULL;
struct node *new_node = malloc(sizeof(struct node));
new_node->value = 1;
new_node->next = first;
first = new_node;
// 添加新节点
struct node *add_to_list(struct node *list,int n){
struct node *new_node;
new_node = malloc(sizeof(struct node));
new_node->value=n;
new_node->next = list;
return new_node;
}
5.3 搜索链表
// 搜索链表
struct node *seatch_list(struct node *list,int n){
struct node *p;
for(p = list;p!=NULL;p=p->next){
if(p->value==n){
return p;
}
}
return NULL;
}
该博客教程视频地址:http://geek99.com/node/1004