Question: given an integer array, the rightmost element is used as the benchmark to sort out the array. The elements greater than the benchmark are placed on the right of the array, the element smaller than this benchmark is placed on the left of it. Do not use temporary arrays.
Idea: First find an element that is greater than the benchmark and exchange the benchmark. At this time, the benchmark element is already in the middle of the array (not the rightmost/middle), Scanning backward from the benchmark, and exchanging if it is less than the benchmark.
Public class arrayparts {public static void main (string [] ARGs) {int [] C = partition (New int [] {2, 3, 5, 1, 6, 4}); For (INT I = 0; I <C. length; I ++) system. out. print (C [I] + ",");} public static int [] substring (INT [] A) {int Len =. length; If (LEN <= 1) return a; int P = A [Len-1]; int I = 0, temp = 0 ;; // for (I = 0; I <Len; I ++) {if (a [I]> P) {temp = A [I]; A [I] = A [Len-1]; A [Len-1] = temp; break;} For (; I <len-1; I ++) {if (a [I + 1] <A [I] & A [I + 1] <p) {temp = A [I + 1]; A [I + 1] = A [I]; A [I] = temp ;}} return ;}}