Loading...
Searching...
No Matches
Implementation Details. More...
#include <algorithm>
#include <cassert>
#include <ctime>
#include <iostream>
#include <vector>
Go to the source code of this file.
namespace sorting for working with vectorsImplementation Details.
Quick sort 3 works on Dutch National Flag Algorithm The major difference between simple quicksort and quick sort 3 comes in the function partition3 In quick_sort_partition3 we divide the vector/array into 3 parts. quick sort 3 works faster in some cases as compared to simple quicksort.
Definition in file quick_sort_3.cpp.
◆ main()Driver program for above functions
Definition at line 184 of file quick_sort_3.cpp.
184 {
185 std::srand(std::time(nullptr));
188 return 0;
189}
static void test_double()
◆ test_double()Test function for double type arrays
Definition at line 160 of file quick_sort_3.cpp.
160 {
161 std::cout << "\nTesting Double type arrays\n";
162 for (int num_tests = 1; num_tests < 21; num_tests++) {
163 size_t size = std::rand() % 500;
164 std::vector<double> arr(size);
165 for (auto &a : arr) {
166 a = double(std::rand() % 500) -
167 250.f;
168 a /= 100.f;
169 }
170
171 std::cout << "Test " << num_tests << "\t Array size:" << size << "\t ";
172 std::vector<double> sorted =
174 if (size < 20) {
175 std::cout << "\t Sorted Array is:\n\t";
176 std::cout << sorted << "\n";
177 }
178 assert(std::is_sorted(std::begin(sorted), std::end(sorted)));
179 std::cout << "\t Passed\n";
180 }
181}
void quicksort(std::vector< T > *arr, int32_t low, int32_t high)
◆ test_int()Test function for integer type arrays
Definition at line 138 of file quick_sort_3.cpp.
138 {
139 std::cout << "\nTesting integer type arrays\n";
140
141 for (int num_tests = 1; num_tests < 21; num_tests++) {
142 size_t size = std::rand() % 500;
143 std::vector<int> arr(size);
144 for (auto &a : arr) {
145 a = std::rand() % 500 - 250;
146 }
147
148 std::cout << "Test " << num_tests << "\t Array size:" << size << "\t ";
150 if (size < 20) {
151 std::cout << "\t Sorted Array is:\n\t";
152 std::cout << sorted << "\n";
153 }
154 assert(std::is_sorted(std::begin(sorted), std::end(sorted)));
155 std::cout << "\t Passed\n";
156 }
157}
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