From bc6fa2f8d7967acd859c0f660cad81199e53b0fb Mon Sep 17 00:00:00 2001 From: Andrew Guschin Date: Thu, 19 May 2022 14:12:12 +0400 Subject: =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D0=BE=D1=82=D1=87=D1=91=D1=82=D0=BE=D0=B2=20=D0=BF?= =?UTF-8?q?=D0=BE=20=D0=BF=D0=B5=D1=80=D0=B2=D1=8B=D0=BC=20=D1=82=D1=80?= =?UTF-8?q?=D1=91=D0=BC=20=D0=BB=D0=B0=D0=B1=D0=B0=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- straight-selection.cpp | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'straight-selection.cpp') 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 &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; } } -- cgit v1.2.3