Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
ugly quick sort
Language:
Ada
Assembly
Bash
C#
C++ (gcc)
C++ (clang)
C++ (vc++)
C (gcc)
C (clang)
C (vc)
Client Side
Clojure
Common Lisp
D
Elixir
Erlang
F#
Fortran
Go
Haskell
Java
Javascript
Kotlin
Lua
MySql
Node.js
Ocaml
Octave
Objective-C
Oracle
Pascal
Perl
Php
PostgreSQL
Prolog
Python
Python 3
R
Rust
Ruby
Scala
Scheme
Sql Server
Swift
Tcl
Visual Basic
Layout:
Vertical
Horizontal
//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"; }
g++
Show compiler warnings
[
+
] Compiler args
[
+
]
Show input
Compilation time: 0.55 sec, absolute running time: 0.14 sec, cpu time: 0 sec, memory peak: 3 Mb, absolute service time: 0.7 sec
edit mode
|
history
|
discussion
10 2 3 0 0 0 -1 -1 0 0 0 2 3 10 Hello, world!