Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
ugly quick sort
//Title of this code #include <iostream> #include <vector> using namespace std; vector<int> quickSort(vector<int> t) { vector<int> less, great, equal; if (t.empty()) return less; int pivot = t[t.size() - 1]; for (typename vector<int>::iterator it = t.begin(); it != t.end(); ++it) { if (*it > pivot) great.push_back(*it); else if (*it < pivot) less.push_back(*it); else equal.push_back(*it); } less = quickSort(less); great = quickSort(great); less.insert(less.end(), equal.begin(), equal.end()); less.insert(less.end(), great.begin(), great.end()); return less; } void print(vector<int>& t) { for (auto i = t.begin(); i != t.end(); ++i) cout << *i << " "; cout << endl; } int main() { vector<int> t; t.push_back(10); t.push_back(2); t.push_back(3); t.push_back(0); t.push_back(0); t.push_back(0); t.push_back(-1); print(t); t = quickSort(t); print(t); std::cout << "Hello, world!\n"; }
run
|
edit
|
history
|
help
0
template inhertinace
replace digits
Lazy String Tokenizer Class
ignat
cppPyClamInher
Float
TraceMarrix
Coin changes
Permute
Microsoft Question - MaxEmployeeAttendence (original question)