Skip to content

Commit 4d6a5a1

Browse files
authored
C++
1 parent f3771b1 commit 4d6a5a1

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

Quick Sort/quick_sort.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
void QuickSort(vector<int>& arr, int left, int right) {
2+
int x = arr[(left + right) / 2];
3+
int i = left, j = right - 1;
4+
while (i <= j)
5+
{
6+
while (arr[i] < x) i++;
7+
while (arr[j] > x) j--;
8+
if (i <= j)
9+
swap(arr[i++], arr[j--]);
10+
}
11+
if (left < j) QuickSort(arr, left, j + 1);
12+
if (i < right) QuickSort(arr, i, right);
13+
}

0 commit comments

Comments
 (0)