SDUT-3398 数据结构实验之排序一:一趟快排(水题)
来源:互联网 发布:淘宝7个层级流量怎么样 编辑:程序博客网 时间:2024/06/05 18:47
数据结构实验之排序一:一趟快排
Time Limit: 1000MS Memory Limit: 65536KB
Submit Statistic
Problem Description
给定N个长整型范围内的整数,要求输出以给定数据中第一个数为枢轴进行一趟快速排序之后的结果。
Input
连续输入多组数据,每组输入数据第一行给出正整数N(N < = 10^5),随后给出N个长整型范围内的整数,数字间以空格分隔。
Output
输出一趟快速排序后的结果,数字间以一个空格间隔,行末不得有多余空格。
Example Input
849 38 65 97 76 13 27 49
Example Output
27 38 13 49 76 97 65 49
Hint
Author
xam
#include <bits/stdc++.h>using namespace std;int a[11111];void Qsort(int low,int high){ int x=a[low],left=low,right=high; if(low>=high)return;///注意递归函数一定要及时return while(left<right) { while(left<right&&a[right]>=x)right--; a[left]=a[right]; while(left<right&&a[left]<=x)left++; a[right]=a[left]; } a[left]=x; /*Qsort(low,left-1); Qsort(left+1,high);*/}int main(){ std::ios::sync_with_stdio(false); int n; while(cin>>n) { for(int i=0;i<n;i++) { cin>>a[i]; } Qsort(0,n-1); for(int i=0;i<n;i++) { if(!i) cout<<a[i]; else cout<<' '<<a[i]; } cout<<endl; } return 0;}
阅读全文
0 0
- SDUT 3398 数据结构实验之排序一:一趟快排
- SDUT-3398-->数据结构实验之排序一:一趟快排
- SDUT-3398 数据结构实验之排序一:一趟快排(水题)
- SDUT OJ 3398 数据结构实验之排序一:一趟快排
- 3398 数据结构实验之排序一:一趟快排
- 3398-数据结构实验之排序一:一趟快排
- 3398 数据结构实验之排序一:一趟快排
- 数据结构实验之排序一:一趟快排
- 数据结构实验之排序一:一趟快排
- SDUT3398数据结构实验之排序一:一趟快排
- 数据结构实验之排序一:一趟快排
- 数据结构实验之排序一:一趟快排
- 数据结构实验之排序一:一趟快排
- 数据结构实验之排序一:一趟快排
- SDUTACM 数据结构实验之排序一:一趟快排
- 数据结构实验之排序一:一趟快排
- 数据结构实验之排序一:一趟快排
- 数据结构实验之排序一:一趟快排
- 期末复习概述
- 如果CEO只给你1个月时间,如何完成从0到1
- linux IANA分配的端口列表
- 论文阅读笔记:DeepRadiologyNet: Radiologist Level Pathology Detection in CT Head Images
- c语言指针字符串体会
- SDUT-3398 数据结构实验之排序一:一趟快排(水题)
- 利用.vcf文件创建手机通讯录文件并导入
- 人工智能的核心和底层是什么?你知道吗?
- vnc远程工具的使用教程
- APP测试要点
- 存储总量达 20T 的 MySQL 实例,如何完成迁移?
- linux的SHELL编程
- js处理数据的一些方法
- [计算最大公因子]Finding the greatest common divisor (gcd) of 2 numbers