summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@gmail.com>2012-07-10 11:14:20 -0400
committerKohei Yoshida <kohei.yoshida@gmail.com>2012-07-10 11:14:20 -0400
commit8ab4bf4ccb1a578a9666d8ba2f8a51b62dcb0d73 (patch)
treed39b42b1164ece45494dc467e84e4afcc16f37c4
parent9c954ad2bdf308d1fa04e456b557a2fe365018db (diff)
Do nothing for a segment of size 1.
-rw-r--r--quick-sort.cpp3
1 files changed, 3 insertions, 0 deletions
diff --git a/quick-sort.cpp b/quick-sort.cpp
index 4e560a9..8e54ca7 100644
--- a/quick-sort.cpp
+++ b/quick-sort.cpp
@@ -10,6 +10,9 @@ typedef std::deque<int> list_t;
size_t partition(list_t& lst, size_t left, size_t right, size_t pivot)
{
+ if (left == right)
+ return left;
+
list_t::value_type pivot_val = lst[pivot];
swap(lst[pivot], lst[right]); // move pivot to end.
size_t store_pos = left;