import javautilArrayList; import javautilRandom; import javaxswingJFrame; import javaxswingJTextArea; public class Text { private static Random rd; private static int[] array; public static void main(String[] args){ Random r = new Random(); array = new int[]; ArrayList<Integer> list = new ArrayList<Integer>(); for(int i=; i<; i++) array = rnextInt(); for(int i=; i<arraylength; i++) Systemoutprint(array+; ;); Systemoutprintln(); int l = Locate(array); for(int i=l; i<arraylength; i++){ listadd(array); } for(int i:list){ Systemoutprint(i+; ;); } } /* 用最快速的方法打乱一个数组而且公平平均 */ private static void Resort(int[] array){ rd = new Random(); int temp; for(int i=; i<arraylength; i++){ int l = rdnextInt(arraylength); //int m = rdnextInt(arraylength); temp = array[]; array[] = array[l]; array[l] = temp; } } /* 给定一个数组找出指定连续n个大于c的子数组所在位置 例如给定{} 指定n=c= 将返回子数组{}所在位置 */ private static int Locate(int[] array int n int c){ int[] list = new int[n]; int i=; int j=; for(i=; i<=arraylengthn; i++){ for(j=; j<n; j++){ list[j] = array[i+j]; if(list[j]>=c) break; } if(j==n) return i; } return ; } /*快速排序*/ private static void QuickSort(int[] array int x int y){ int xx = x yy = y; int k = array[xx]; if(x>=y) return; while(xx != yy){ while(xx<yy && array[yy]>=k) yy;; array[xx] = array[yy]; while(xx<yy && array[xx]<=k) xx++; array[yy] = array[xx]; } array[xx] = k; QuickSort(array xxx); QuickSort(array xx+ y); } } |