퀵 정렬은 pivot을 하나 구해놓고, pivot보다 작은 수와 pivot보다 큰 수의 위치를 바꿔주는 정렬이다. 이 정렬은 이름과 같이 정렬 중 빠른 정렬로 많이 사용된다.

위의 과정을 start와 end가 만날 때까지 반복한다.
start와 end가 만났다면, pivot과 start의 위치를 바꿔준다.
정렬이 모두 끝날 때까지 반복한다.
퀵 정렬을 java로 구현하면 아래와 같다.
public int majorityElement(int[] nums) {
//정렬
quickSort(nums, 0, nums.length-1);
}
private void quickSort(int[] arr, int start, int end) {
if (start >= end) {
return;
}
int pivot = start;
int lo = start + 1;
int hi = end;
while (lo <= hi) {
while (lo <= end && arr[lo] <= arr[pivot]) {
lo++;
}
while (hi > start && arr[hi] > arr[pivot]) {
hi--;
}
if (lo > hi) {
int temp = arr[hi];
arr[hi] = arr[pivot];
arr[pivot] = temp;
} else {
int temp = arr[lo];
arr[lo] = arr[hi];
arr[hi] = temp;
}
}
quickSort(arr, start, hi - 1);
quickSort(arr, hi + 1, end);
}