Skip to content

Commit 0d0d2e2

Browse files
Update quick_sort.cpp
1 parent 8790487 commit 0d0d2e2

File tree

1 file changed

+5
-13
lines changed

1 file changed

+5
-13
lines changed

sorting/quick_sort.cpp

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,24 @@
33
using namespace std;
44

55
void quickSort(vector<int>&,int,int);
6-
76
int partition(vector<int>&, int,int);
87

98
int main()
109
{
11-
vector<int> A = {6,10,13,5,8,3,2,25,4,11};
10+
vector<int> A = {10,9,8,7,6,5,4,3,2,1};
1211
int start = 0;
13-
int end = 10;
14-
12+
int end = (int)A.size();
1513
cout << "Before:" << endl;
1614
for(auto value : A)
1715
cout << value <<" ";
1816
cout << endl;
19-
2017
quickSort(A, start, end);
21-
2218
cout << "After: " << endl;
2319
for(auto value : A)
2420
cout << value <<" ";
2521
cout << endl;
2622
}
2723

28-
2924
void quickSort(vector<int>& A, int start,int end)
3025
{
3126
int pivot;
@@ -43,17 +38,14 @@ int partition(vector<int>& A, int start,int end)
4338
int x = A[start];
4439
int i = start;
4540
int j;
46-
4741
for(j = start+1; j < end; j++)
4842
{
49-
if(A[j]<=x)
50-
{
43+
if(A[j]<=x)
44+
{
5145
i=i+1;
52-
swap(A[i],A[j]);
46+
swap(A[i],A[j]);
5347
}
54-
5548
}
56-
5749
swap(A[i],A[start]);
5850
return i;
5951
}

0 commit comments

Comments
 (0)