Given an array, find the number k in the array. The implementation code is as follows:
Package com.threeTop.www; /** * Find out the number of K in the array * @author WJGS * * */public class Findk {public static void found (Int[]array,int begin,int end,int
k) {int i=partition (array,begin,end);
if (i+1>k) {//left half, recursive lookup find (array,begin,i-1,k);
else if (i+1<k) {//Right half part, recursive lookup find (array,i+1,end,k);
}else {System.out.println ("found the" +k+ "large number is:" +array[i]);
Return }/** * Quick sort per round * @param array * @param begin * @param end * @return/private static int partition (int[)
array, int begin, int end) {if (begin<end) {//first number as Datum int key=array[begin]; while (Begin<end) {while (Begin<end&&array[end]>key) {End
--;
} if (Begin<end) {array[begin]=array[end];
begin++;
while (Begin<end&&array[begin]<key) {begin++; } if (BegiN<end) {Array[end]=array[begin];
end--;
}} Array[begin]=key;
return begin;
public static void Main (string[] args) {int []array={1,5,7,9,2,4,6,8,10,12,11,14,15,13};
Findk.find (Array, 0,array.length-1, 8);
}
}