解题思路:
注意事项:
参考代码:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner=new Scanner(System.in);
int n=10,count=0;
int arr[]=new int[n];
for(int i=0;i<n;i++){
int num=scanner.nextInt();
if(num!=0){
arr[i]=num;
count++;
}
else{
break;
}
}
quick_sort(arr, 0, count-1 );
for (int i = 0; i < count; i++) {
System.out.print(arr[i] + "\t");
}
}
public static void quick_sort(int arr[], int l, int r) {
if (l >= r) return;
int i = l - 1, j = r + 1, x = arr[l + (int)(Math.random() * (r - l + 1))];
while (i < j) {
do i++; while (arr[i] < x);
do j--; while (arr[j] > x);
if (i < j) swap(arr, i, j);
}
quick_sort(arr, l, j);
quick_sort(arr, j + 1, r);
}
public static void swap(int arr[], int a, int b) {
int temp = arr[b];
arr[b] = arr[a];
arr[a] = temp;
}
}
0.0分
0 人评分
C语言程序设计教程(第三版)课后习题10.5 (C语言代码)浏览:733 |
C语言程序设计教程(第三版)课后习题8.6 (C语言代码)浏览:582 |
C语言程序设计教程(第三版)课后习题8.3 (Java代码)浏览:1374 |
矩阵乘法 (C++代码)浏览:1462 |
校门外的树 (C语言代码)浏览:961 |
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:1162 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:543 |
求圆的面积 (C语言代码)浏览:1670 |
蛇行矩阵 (C语言代码)浏览:536 |
C语言程序设计教程(第三版)课后习题5.6 (C语言代码)浏览:902 |