What you want should be something like one step of quick sort.
I modify a little so that you can pass an pivot needed as a parameter :
public static void main(String[] args) {
int[] a = new int[]{9,7,13,24,2,16,3,10};
System.out.println(partition(a,9));//use value 9 as pivot
System.out.println(Arrays.toString(a));
}
private static int partition(int[] a, int pivot){
int pivotIndex = 0;
for(int i=0;i<a.length;i++){//find initial pivot Index
if(a[i]==pivot) {
pivotIndex = i;
break;
}
}
int low = 0;
int high = a.length-1;
while(low<high){
while(low<high&&a[high]>=pivot) high--;
a[pivotIndex] = a[high];
pivotIndex = high;
while(low<high&&a[low]<=pivot) low++;
a[pivotIndex] = a[low];
pivotIndex= low;
}
//Actual pivotIndex finded
a[pivotIndex] = pivot;
return pivotIndex;
}
output:
3
[3, 7, 2, 9, 24, 16, 13, 10]