3、
/**
* 得到数组元素位次
* @param a
*/
public static void GetPos(int a[], int val)
{
int pos = a.length;
for(int i = 0; i < a.length; i++)
{
if(val == a[i])
{
pos = i;
break;
}
}
if(a.length == pos)
{
System.out.println("not found");
}
else
{
System.out.println(partation(a, pos, 0, a.length - 1));
}
}
/**
* 分块
* @param a
* @param pos
* @param low
* @param high
* @return
*/
public static int partation(int a[], int pos, int low, int high)
{
int temp = a[pos];
while(low < high)
{
while(low < high && temp <= a[high])
{
high--;
}
a[pos] = a[high];
a[high] = temp;
while(low < high && temp >= a[low])
{
low++;
}
a[high] = a[low];
a[low] = temp;
}
return a.length - low;
}