Quick Sort with random pivot in Java -
I have been assigned a quick sequence with a random point point (because it is believed that the most efficient / Is the safest way), even though I was working on a bogart someone can direct me on how to do this? And can someone help me to see if I can save it in some way? Can anyone help me to see Bogorot? Public static zero instant (int [] target, int lo, int hi) {if (hi-lo == 0) {return;} random number generator = new random (); Int Peivot = (number generator. NxITINTINTINITIT + take); Int high; (If high (target = high)> target [pivot]) {// if smaller than the pivot, then stay very far (high-smoke == 1) {int temp = target [high]; Targeted to [high] = target [pivot]; Target [axle] = floating; } And {int temp1 = target [pivot]; Int temp2 = target [pivot + 1]; Target [axle] = target [high]; Target [pivot + 1] = temp1; Targeted to [high] = temp2; }}} Int lower; {Low (Target = Low)> Goal [Pivot]) {// If smaller than the pivot, then stay very far (if at least == 1) {int (low = low; low> pituit; low ++) temporary = Goal [low]; Targeted [low] = target [pivot]; Target [axle] = floating; } And {int temp1 = target [pivot]; Int temp2 = target [paw-1]; Target [pivot] = target [decrease]; Target [pivot 1] = temp1; Targeted [low] = temp2; }}} If (low-low> 0) {quick (target, low, low-1); } If (high-height> 0) {quick (target, high + 1, hi); }}
See this proxy for in-fighting (from Wikipedia): < Pivot value: = array [pivotindx] swap array [pivotindex] and array [right] // run the run to end the array. Do: Left to right for = I - 1 // left ≤ I & lt; Right if array [i] ≤ Pivat value swap array [i] and array [storeIndex] storeIndex: storeIndex + 1 swap array [storeIndex] and array [right] // move its final place to move its notch INX
Through the entire array it announces the loops (except for the last indicator) the axis does not swap till the end. The value of the pivot in your code varies through the loop which is not right.
Each time the swap target (above store_index) should be changed.
In addition, you only need to swap values from smoke to left if all the lower values are on the left, then the higher values will end on the right.
Comments
Post a Comment