summaryrefslogtreecommitdiff
path: root/straight-selection.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'straight-selection.cpp')
-rw-r--r--straight-selection.cpp10
1 files changed, 3 insertions, 7 deletions
diff --git a/straight-selection.cpp b/straight-selection.cpp
index ff5a7b6..86c8f94 100644
--- a/straight-selection.cpp
+++ b/straight-selection.cpp
@@ -7,18 +7,14 @@ straight_selection(std::vector<T> &array)
{
for (int i = 0; i < array.size(); ++i)
{
- int k = i;
- int x = array[i];
for (int j = i; j < array.size(); ++j)
{
- if (array[j] < x)
+ if (array[j] < array[i])
{
- k = j;
- x = array[j];
+ std::swap(array[i], array[j]);
+ break;
}
}
- array[k] = array[i];
- array[i] = x;
}
}