change pivot in my quickSort algorithm java

后端 未结 3 1778
野性不改
野性不改 2021-01-26 13:01

I have implemented a working quickSort algorithm using the first element in the array as the pivot, that look like this:

public int[] quickSort( int[] a, int st         


        
3条回答
  •  旧时难觅i
    2021-01-26 13:12

    You could simply swap the pivot you chose with the first element in the array before you start sorting, that way it'll work exactly as before.

    int l = start;
    int r = end;
    
    this.swap(a, choosePivot(), start); 
    int pivotIndex = start; 
    

提交回复
热议问题