C语言——单链表创建练习题
2013-03-13 15:20
344 查看
/* 创建单链表,并将其打印出来。数据使用了随机数; */ #include <stdio.h> #include <stdlib.h> #include <time.h> #define N 16 typedef struct node *link; struct node { int item; link next; }; link NODE(int item, link next) { link t = malloc(sizeof *t); t->item = item; t->next = next; return t; } void show_list(link head) { link t; for (t=head; t; t=t->next) printf("%3d", t->item); printf("\n"); } link insert_node(link head, int item) { link x, y; for (y=head, x=y; y; x=y, y=y->next) if (item <= y->item) break; if (x==y) head = NODE(item, head); else x->next = NODE(item, y); return head; } int main() { int i; link head = NULL; srand(time(NULL)); for (i=0; i<N; i++) head = insert_node(head, rand()%100); show_list(head); return 0; }
相关文章推荐
- C语言——单链表排序练习题
- C语言单链表的创建和添加结点
- c语言创建单链表
- C语言实现单链表的创建和添加结点
- C语言单链表的创建、插入、查找、删除、求长、排序、遍历
- c语言数据结构之顺序表单链表的创建及功能函数
- C语言之数据结构的顺序单链表创建,插入和删除操作
- C语言进阶-第18讲:单链表的遍历、创建、插入和删除结点
- 【C语言】-单链表的创建和输出
- C语言实现单链表的初始化、创建、遍历等操作
- c语言之单链表的创建及排序
- C语言:单链表的创建,打印及销毁
- c语言实现对传统单链表的创建、添加 遍历 删除 反转元素操作
- C语言创建单链表
- C语言单链表的创建和简单使用
- C语言实现创建单链表及求长度
- 单链表的创建和反转(C语言)
- C语言实现单链表的创建、插入、删除
- c语言实现单链表的操作:创建,删除,插入,反转, 排序等
- C语言创建单链表,输出单链表的内容。