(std::vector<int> &arr,
intstart,
intend)
36 intindex = start - 1;
38 for(
intj = start; j < end; j++) {
39 if(arr[j] <= pivot) {
40std::swap(arr[++index], arr[j]);
44std::swap(arr[index + 1], arr[end]);
60std::stack<int>
stack;
62 intend = arr.size()-1;
66 while(!
stack.empty())
73 intpivotIndex =
partition(arr,start,end);
75 if(pivotIndex -1 > start)
97std::vector<int> case1={100,534,1000000,553,10,61,2000,238,2756,9,12,56,30};
98std::cout<<
"TEST 1\n";
99std::cout<<
"Before: \n";
100 for(
autox : case1) std::cout<<x<<
",";
103assert(std::is_sorted(std::begin(case1),std::end(case1)));
104std::cout<<
"Test 1 succesful!\n";
105std::cout<<
"After: \n";
106 for(
autox : case1) std::cout<<x<<
",";
110std::vector<int> case2={-10,-2,-5,-2,-3746,-785,-123, -452, -32456};
111std::cout<<
"TEST 2\n";
112std::cout<<
"Before: \n";
113 for(
autox : case2) std::cout<<x<<
",";
116assert(std::is_sorted(std::begin(case2),std::end(case2)));
117std::cout<<
"Test 2 succesful!\n";
118std::cout<<
"After: \n";
119 for(
autox : case2) std::cout<<x<<
",";
for std::invalid_argument
void push(const value_type &item)
void iterativeQuickSort(std::vector< int > &arr)
The main sorting function.
int partition(std::vector< int > &arr, int start, int end)
The partition function sorts the array from start to end and uses the last element as the pivot.
void tests()
Self-test implementations.
int main()
Main function.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4