SDUT2121数据结构实验之链表六:有序链表的建立
2016-07-23 11:20
337 查看
#include<bits/stdc++.h> using namespace std; struct node { int data; struct node *next; }*head,*p,*q; void insertsort(int n) { struct node *x,*y; while(n--) { q=(struct node *)malloc(sizeof(struct node)); scanf("%d",&q->data); x=head->next; y=head; while(x!=NULL) { if(q->data<x->data) { y->next=q; q->next=x; break; } y=x; x=x->next; } if(x==NULL) { y->next=q; q->next=NULL; } } } void print(struct node *head) { p=head->next; while(p) { printf("%d",p->data); if(p->next) printf(" "); p=p->next; } } int main() { head=(struct node *)malloc(sizeof(struct node)); head->next=NULL; int n; scanf("%d",&n); insertsort(n); print(head); }
相关文章推荐
- SDUT 3373 数据结构实验之查找一:二叉排序树
- 数据结构之图的深度优先遍历和广度优先遍历
- 数据结构中的各种排序方法小结(JS实现)
- 1sql数据结构操作
- SDUT2119数据结构实验之链表四:有序链表的归并
- 复习(数据结构):队列:c语言
- 优先队列与堆
- SDUT3341数据结构实验之二叉树二:遍历二叉树
- Redis与Java - 数据结构
- Redis与Java - 数据结构
- Redis与Java - 数据结构
- Core_1_数据结构和函数
- 【排序】稳定排序和不稳定排序
- 数据结构中的各种排序方法小结(JS实现)
- 数据结构 线性链表栈
- SDUT3343数据结构实验之二叉树四:还原二叉树
- SDUT2137数据结构实验之求二叉树后序遍历和层次遍历
- 数据结构-----------B树
- 数据结构与算法 1 :基本概念,线性表顺序结构,线性表链式结构,单向循环链表
- SDUT2136数据结构实验之二叉树的建立与遍历