# 道一笔试题(编程部分)

2014-01-30 06:30:01 阅读( 159 )

import java.util.ArrayList;
import java.util.Random;
import javax.swing.JFrame;
import javax.swing.JTextArea;
public class Text {
private static Random rd;
private static int[] array;
public static void main(String[] args){
Random r = new Random();
array = new int[50];
ArrayList list = new ArrayList();
for(int i=0; i<50; i++)
array = r.nextInt(15);
for(int i=0; i<array.length; i++)
System.out.print(array+” “);
System.out.println();
int l = Locate(array,3,8);
for(int i=l; i<array.length; i++){
}
for(int i:list){
System.out.print(i+” “);
}

}

/*

*/
private static void Resort(int[] array){
rd = new Random();
int temp;
for(int i=0; i<array.length; i++){
int l = rd.nextInt(array.length);
//int m = rd.nextInt(array.length);
temp = array[0];
array[0] = array[l];
array[l] = temp;
}

}

/*

*/
private static int Locate(int[] array, int n, int c){
int[] list = new int[n];
int i=0;
int j=0;
for(i=0; i<=array.length-n; i++){
for(j=0; j<n; j++){
list[j] = array[i+j];
if(list[j]>=c)
break;
}
if(j==n)
return i;
}
return -1;

}

/*快速排序*/
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=k) yy–;
array[xx] = array[yy];
while(xx<yy && array[xx]<=k) xx++;
array[yy] = array[xx];
}
array[xx] = k;
QuickSort(array, x,xx-1);
QuickSort(array, xx+1, y);

}
}