内容简介:问题描述输入格式输出格式
问题描述
快速排序是最经常使用的一种 排序 方式,对于给定的n个数组成的一个数组,请使用快速排序对其进行排序。
输入格式
第一行一个数N。
输出格式
共N行,每行一个数,表示所求序列。
样例输入
5
1
4
2
3
样例输出
1
2
3
4
数据规模和约定
共10组数据。
对100%的数据,N<=10^5,所有数均为非负数且在int范围内。
package algo59;
// 自己写的快速排序在遇到一个极端情况,会出现超时
import java.io.*;
import java.util.Arrays;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(reader.readLine());
num = new int[n];
for (int i = 0; i < n; i++) {
num[i] = Integer.parseInt(reader.readLine());
}
reader.close();
// quickSort();
Arrays.sort(num);
for (int i = 0; i < num.length; i++) {
System.out.println(num[i]);
}
}
private static int[] num;
// private static void quickSort() {
// quickSort(0, num.length - 1);
// }
//
// private static void quickSort(int l, int r) {
// if (l < r) {
// int pivot = partion(l, r);
// quickSort(l, pivot - 1);
// quickSort(pivot + 1, r);
// }
// }
//
// private static int partion(int l, int r) {
// swap(l, (l + r) / 2);
// int pivot = l;
// while (true) {
// while (l <= r && num[l] < num[pivot]) {
// l++;
// }
// while (l <= r && num[r] > num[pivot]) {
// r--;
// }
//
// if (l < r) {
// swap(l, r);
// l++;
// r--;
// } else {
// break;
// }
// }
// swap(r, pivot);
// return r;
// }
//
// private static void swap(int i, int j) {
// int temp = num[i];
// num[i] = num[j];
// num[j] = temp;
// }
}
❤❤点击这里 -> 订阅PAT、蓝桥杯、GPLT天梯赛、LeetCode题解离线版❤❤
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
猜你喜欢:- 蓝桥杯 ADV-126 算法提高 扫雷
- 蓝桥杯 ADV-133 算法提高 彩票
- 蓝桥杯 ALGO-112 算法训练 暗恋
- 蓝桥杯 算法训练 审美课 java
- 蓝桥杯 ADV-233 算法提高 队列操作
- 蓝桥杯 ADV-189 算法提高 连接乘积
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
TensorFlow:实战Google深度学习框架(第2版)
顾思宇、梁博文、郑泽宇 / 电子工业出版社 / 2018-2-1 / 89
TensorFlow是谷歌2015年开源的主流深度学习框架,目前已得到广泛应用。《TensorFlow:实战Google深度学习框架(第2版)》为TensorFlow入门参考书,旨在帮助读者以快速、有效的方式上手TensorFlow和深度学习。书中省略了烦琐的数学模型推导,从实际应用问题出发,通过具体的TensorFlow示例介绍如何使用深度学习解决实际问题。书中包含深度学习的入门知识和大量实践经......一起来看看 《TensorFlow:实战Google深度学习框架(第2版)》 这本书的介绍吧!