比如2 1 5 6 8 3,要输入m=3个大的数,就输出 5 6 8(不用排序)!
import java.util.Scanner; public class 求m大个数 { private static int a[] = {10,23,25,62,10,2040}; private static int m = 0; private static void getResult(int s, int e) { // TODO Auto-generated method stub int k = a[s]; int i = s; int j = e; while(i != j){ while(i<j && k<=a[j]){ j--; } int temp = a[i]; a[i] = a[j]; a[j] = temp; while(i<j && k>=a[i]){ i++; } temp = a[i]; a[i] = a[j]; a[j] = temp; } int count = a.length-i; if(count == m){ return; }else if(count > m){ getResult(j+1,e); }else{ getResult(s,i); } } /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Scanner sc = new Scanner(System.in); m = sc.nextInt(); getResult(0,a.length-1); for(int i=m; i<a.length; i++){ System.out.print(a[i]+" "); } System.out.println(); } }