数据结构之简单链表(尾部插入数据)
2011-11-30 15:59
274 查看
#include <stdio.h> #include <stdlib.h> typedef struct node { int key; struct node *Next; }Node; void Insert(int num,Node *head) { Node *L = NULL; Node *p = NULL; L = head; while (L->Next != NULL) { L = L->Next;//遍历找到尾节点 } p = (Node *) malloc (sizeof(Node));//开辟新的节点 p->key = num;//赋值 p->Next = NULL;//设置为尾节点 L->Next = p;//挂在原来尾节点之后 } void Print_List(Node *head) { Node *p = head->Next; while(p != NULL)//遍历打印节点值 { printf("%d->", p->key); p = p->Next; } printf("\n"); } int main() { int i; Node *head = (Node *)malloc(sizeof(Node)); head->Next = NULL;//建立空表头 for (i=0; i<10; i++) { Insert(i, head); } Print_List(head); system("PAUSE"); return 0; }
相关文章推荐
- 数据结构之简单链表(尾部插入数据)
- 数据结构之简单链表(头部插入数据,查找,删除指定数据)
- 重学数据结构 简单链表 倒叙,正序插入、常规显示、递归显示
- 数据结构:单链表(二)之链表节点排序,升序插入数据,删除指定的所有节点,翻转链表操作
- 链表插入元素的三种递归实现 -- 简单递归,数据累加器,函数累加器
- 数据结构示例之由尾部插入新元素的链表
- 【郝斌数据结构自学笔记】16-23_链表的定义与分类_链表节点插入与删除_每一个链表节点的数据类型该如何表示的问题
- 数据结构--单链表实现栈(头部插入数据的链表)
- 很简单的数据结构:链表线性存储的创建、取数据、数据添加、数据插入、数据删除
- 数据结构学习二 数据结构之链表图解版【创建,遍历,删除,插入】
- mysql 如何查询插入数据表和数据结构
- 数据结构链表的简单处理
- 数据结构和算法设计专题之---单链表中在指定的节点前面插入以及删除一个节点
- 数据结构之链表与数组(二) -单向链表上的简单操作问题
- C语言中链表任意位置怎么插入数据?然后写入文件中?
- 简单的介绍数据结构的里的(数据 数据元素 数据项 数据对象)
- 【数据结构与算法】(二) c 语言链表的简单操作
- AAA如何插入几十万条数据 PL/SQL 调试存储过程简单实例
- 链表操作之插入数据
- 数据结构—双向链表插入数据和反置实现