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 ...
随机推荐
- 什么是jsonp?——使用jsonp解决跨域请求问题
我们在使用ajax请求的时候经常会产生跨域问题,这是由于浏览器的同源策略导致的.所谓同源,即域名.协议.端口均相同,否则不管是静态页面还是动态网页或者web服务都无法通过ajax正常请求.有时候,我们 ...
- class function
type TTest = class public class function sayHello :String; function saybye:String; ...
- 通过DG_BROKE搭建Oracle11g_adg
1.环境 db_primary db_stanby db版本 11.2.0.4.0 11.2.0.4.0 os版本 centos 6.4 centos 6.4 db_unique_name newte ...
- NMS:Non-maximum Suppression学习笔记
非极大值抑制可看成一种局部极大值搜索,这里的局部极大值要比他的邻域值都要大.这里的邻域表示有两个参数:维度和n-邻域.维度有1-D,2-D,3-D...:至于n值根据具体情况设置.举个例子:一维的情况 ...
- 对get post请求的封装
HttpUtil.java package com.dhc.task.wx.util; import java.io.BufferedReader; import java.io.IOExceptio ...
- Screen - BOM对象
Screen 对象 Screen 对象包含有关客户端显示屏幕的信息. 注释:没有应用于 screen 对象的公开标准,不过所有浏览器都支持该对象. Screen 对象属性 属性 描述 availHei ...
- 594. Longest Harmonious Subsequence强制差距为1的最长连续
[抄题]: We define a harmonious array is an array where the difference between its maximum value and it ...
- 下载Redis
1.下载当前Redis 官网:https://redis.io/ 当前稳定版本是4.0.11,如下图,点Download it下面的链接进行下载 2.下载历史版本的Resis 网址: http://d ...
- Luogu 4869 albus就是要第一个出场
BZOJ 2844 被NOIP模拟赛题弄自闭了QuQ. 因为本题要求异或,所以自然地构造出线性基,假设本题中给出的数有$n$个,而我们构造出的线性基大小为$m$,那么每一个可以异或出来的数相当于出现了 ...
- U14.04 teamviewer install
转载http://www.cnblogs.com/kunyuanjushi/p/5205639.html 安装i386库 sudo apt-get install libc6:i386 libgcc1 ...