> For the complete documentation index, see [llms.txt](https://luj.gitbook.io/code/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://luj.gitbook.io/code/common-method/sorting/quick-sort.md).

# Quick Sort

1. left <= right  错开
2. A\[left] < pivot, A\[right] > pivot 找到大于等于/小于等于 -- 均分
3. pivot -> start and end
4. start-right, left-end

```java
public class Solution {
    /**
     * @param A: an integer array
     * @return: nothing
     */
    public void sortIntegers2(int[] A) {
        // write your code here
        quickSort(A, 0, A.length - 1);
    }

    private void quickSort(int[] A, int start, int end) {
        if (start >= end) {
            return;
        }

        int pivot = A[(start + end) / 2];
        int left = start, right = end;
        while (left <= right) {
            while (left <= right && A[left] < pivot) {
                left++;
            }
            while (left <= right && A[right] > pivot) {
                right--;
            }
            if (left <= right) {
                int temp = A[left];
                A[left++] = A[right];
                A[right--] = temp;
            }
        }
        quickSort(A, start, right);
        quickSort(A, left, end);
    }
}
```
