SDUT OJ 数据结构实验之链表六:有序链表的建立
数据结构实验之链表六:有序链表的建立
Problem Description
Input
第二行输入N个无序的整数。
Output
Sample Input
6
33 6 22 9 44 5
Sample Output
5 6 9 22 33 44
Hint
不得使用数组!
一个一个地插入即可;
#include <stdio.h>
#include <stdlib.h>
struct node
{
int data;
struct node *next;
};
int main()
{
struct node *head, *p, *q, *r;
head = (struct node *)malloc(sizeof(struct node));
head->next = NULL;
int i, n;
scanf("%d",&n);
p = (struct node *)malloc(sizeof(struct node));
scanf("%d",&p->data);
p->next = NULL;
head->next = p;
for(i=1; i<n; i++){
p = (struct node *)malloc(sizeof(struct node));
scanf("%d",&p->data);
p->next = NULL;
q = head;
r = q->next;
while(r&&r->data<p->data){
q = q->next;
r = q->next;
}
p->next = q->next;
q->next = p;
}
p = head->next;
while(p->next)
{
printf("%d ",p->data);
p = p->next;
} printf("%d\n",p->data);
return 0;
}
SDUT OJ 数据结构实验之链表六:有序链表的建立的更多相关文章
- SDUT OJ 数据结构实验之图论六:村村通公路(最小生成树)
数据结构实验之图论六:村村通公路 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Problem Descri ...
- SDUT OJ 数据结构实验之二叉树六:哈夫曼编码
数据结构实验之二叉树六:哈夫曼编码 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Problem Descr ...
- SDUT 3403 数据结构实验之排序六:希尔排序
数据结构实验之排序六:希尔排序 Time Limit: 1000MS Memory Limit: 65536KB Submit Statistic Problem Description 我们已经学习 ...
- SDUT 3345 数据结构实验之二叉树六:哈夫曼编码
数据结构实验之二叉树六:哈夫曼编码 Time Limit: 1000MS Memory Limit: 65536KB Submit Statistic Problem Description 字符的编 ...
- SDUT 3362 数据结构实验之图论六:村村通公路
数据结构实验之图论六:村村通公路 Time Limit: 1000MS Memory Limit: 65536KB Submit Statistic Problem Description 当前农村公 ...
- SDUT OJ 数据结构实验之链表四:有序链表的归并
数据结构实验之链表四:有序链表的归并 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Problem Desc ...
- SDUT OJ 数据结构实验之链表九:双向链表
数据结构实验之链表九:双向链表 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Problem Descrip ...
- SDUT OJ 数据结构实验之链表八:Farey序列
数据结构实验之链表八:Farey序列 Time Limit: 10 ms Memory Limit: 600 KiB Submit Statistic Discuss Problem Descript ...
- SDUT OJ 数据结构实验之链表七:单链表中重复元素的删除
数据结构实验之链表七:单链表中重复元素的删除 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Problem ...
随机推荐
- Delphi 解压缩 ZipForge
ZipForge http://www.componentace.com/zip_component_zip_delphi_zipforge.htm downLoad http://www.compo ...
- Bootstrap日期插件中文实现
Bootstrap的相关JS和CSS直接跳过. <script type="text/javascript" src="static/js/jquery-1.9.1 ...
- Java调用Webservice(asmx)的几个例子
Java调用Webservice(asmx)的几个例子 2009-06-28 17:07 写了几个调用例子: 1. import org.apache.axis.client.*;import org ...
- mysql之提示符
MySQL常用的简单的命令: mysql> PROMPT \u@\h \d> PROMPT set to '\u@\h \d>' root (none)>USE test Da ...
- Mysql 设置外部访问
mysql> use mysql; mysql> GRANT ALL ON *.* TO user@' WITH GRANT OPTION; mysql -h172. -uuser -p1 ...
- HTML中禁用表中控件的两种方法与区别
在网页的制作过程中,我们会经常使用到表单.但是有时候我们会希望表单上的控件是不可修改的,比如在修改密码的网页中,显示用户名的文本框就应该是不可修改状态的. 在html中有两种禁用的方法,他们分别是: ...
- 501. Find Mode in Binary Search Tree查找BST中的众数
[抄题]: Given a binary search tree (BST) with duplicates, find all the mode(s) (the most frequently oc ...
- Flask框架 之 路由和视图详解
路由+视图 我们之前了解了路由系统是由带参数的装饰器完成的. 路由本质:装饰器和闭包实现的. 路由设置的两种方式 来看个例子. @app.route('/index') def index(): re ...
- 何为软件的Alpha、Beta、RC和GA发布版本?
简介 一个软件或者一个功能在发布时,通常会有Beta版这么一说.我很熟悉,差不多知道是什么意思,但没去深究,感觉上就是一个可以用但不保证功能稳定的版本. 直到昨天我看到了 MariaDB 数据库发布标 ...
- [GO]随机生成四们数字
package main import ( "math/rand" "time" "fmt" ) func InitData(p *int) ...