SDUT OJ 数据结构实验之排序八:快速排序
数据结构实验之排序八:快速排序
Problem Description
Input
Output
Sample Input
8
49 38 65 97 76 13 27 49
Sample Output
13 27 38 49 49 65 76 97
利用递归进行排序
#include <stdio.h>
#include <stdlib.h>
#define N 110000
void qusort( int *a, int lt, int rt )
{
if(lt >= rt) return;
int i = lt, j = rt, key = a[lt];
while(i<j)
{
while(i<j && a[j] >= key)
j--;
a[i] = a[j];
while(i<j && a[i] <= key)
i++;
a[j] = a[i];
}
a[i] = key;
qusort( a, lt, i-1 );
qusort( a, i+1, rt );
}
int main()
{
int n, i;
int a[N];
while(~scanf("%d", &n))
{
for(i=0; i<n; i++)
scanf("%d", &a[i]);
qusort ( a, 0, n-1 );
for(i=0; i<n-1; i++)
printf("%d ", a[i]);
printf("%d\n", a[i]);
}
return 0;
}
SDUT OJ 数据结构实验之排序八:快速排序的更多相关文章
- SDUT OJ 数据结构实验之排序二:交换排序
数据结构实验之排序二:交换排序 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Problem Descrip ...
- SDUT OJ 数据结构实验之排序一:一趟快排
数据结构实验之排序一:一趟快排 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Problem Descrip ...
- SDUT OJ 数据结构实验之图论八:欧拉回路
数据结构实验之图论八:欧拉回路 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Problem Descrip ...
- SDUT OJ 数据结构实验之二叉树八:(中序后序)求二叉树的深度
数据结构实验之二叉树八:(中序后序)求二叉树的深度 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Probl ...
- SDUT OJ 数据结构实验之排序四:寻找大富翁
数据结构实验之排序四:寻找大富翁 Time Limit: 200 ms Memory Limit: 512 KiB Submit Statistic Discuss Problem Descripti ...
- SDUT OJ 数据结构实验之排序三:bucket sort
数据结构实验之排序三:bucket sort Time Limit: 250 ms Memory Limit: 65536 KiB Submit Statistic Discuss Problem D ...
- SDUT OJ 数据结构实验之链表八:Farey序列
数据结构实验之链表八:Farey序列 Time Limit: 10 ms Memory Limit: 600 KiB Submit Statistic Discuss Problem Descript ...
- SDUT 3401 数据结构实验之排序四:寻找大富翁.!
数据结构实验之排序四:寻找大富翁 Time Limit: 150MS Memory Limit: 512KB Submit Statistic Problem Description 2015胡润全球 ...
- SDUT 3399 数据结构实验之排序二:交换排序
数据结构实验之排序二:交换排序 Time Limit: 1000MS Memory Limit: 65536KB Submit Statistic Problem Description 冒泡排序和快 ...
随机推荐
- 定时器Quartz ClassNotFound org.springframework.scheduling.quartz.SchedulerFactoryBean
转自:https://blog.csdn.net/truong/article/details/37508003 没有添加spring-context-support-3.2.4.RELEASE.ja ...
- Windows下Git中正确显示中文的设置方法
Windows下Git中正确显示中文的设置方法 具体设置方法如下: 进入目录etc:$ cd /etc 1. 编辑 gitconfig 文件:$ vi gitconfig.在其中增加如下内容: [gu ...
- sql server2008 跨服务器之间复制表数据
首先2个数据库要能互相访问,在本地数据库用 select * into 新表 from opendatasource('SQLOLEDB','Data Source=远程数据库IP;User ID=用 ...
- SSH隧道技术简介
本文的受众如果你遇到了以下问题,那么你应该阅读这篇文章 我听说过这种技术,我对它很感兴趣 我想在家里访问我在公司的机器(写程序,查数据,下电影). 公司为了防止我们用XX软件封锁了它的端口或者服务器地 ...
- Weblogic的安装、配置与应用部署
1. Weblogic安装 1.1 Linux下安装过程 安装环境: 操作系统: redhat-release-5Server-5.4.0.3 Weblogic版本: Weblogic 9.24 1) ...
- 724. Find Pivot Index 找到中轴下标
[抄题]: Given an array of integers nums, write a method that returns the "pivot" index of th ...
- spring框架 事务 注解配置方式
user=LF password=LF jdbcUrl=jdbc:oracle:thin:@localhost:1521:orcl driverClass=oracle.jdbc.driver.Ora ...
- Python 网络爬虫 009 (编程) 通过正则表达式来获取一个网页中的所有的URL链接,并下载这些URL链接的源代码
通过 正则表达式 来获取一个网页中的所有的 URL链接,并下载这些 URL链接 的源代码 使用的系统:Windows 10 64位 Python 语言版本:Python 2.7.10 V 使用的编程 ...
- ROS indigo 删除和安装
删除比较容易: sudo apt-get remove ros-jade-desktop-full 但是如果怕删不干净可以采用: sudo apt-get remove ros-* ,但是不确定会 ...
- activex打包
http://www.cnblogs.com/weiwin/p/4493835.html activeX 打包 原文 http://www.docin.com/p-409284488.html C ...