From af5fc02a3ed8d237193d40f8cef6ecb96e19a741 Mon Sep 17 00:00:00 2001 From: Susmit-A Date: Sat, 27 Oct 2018 00:19:02 +0530 Subject: [PATCH] Added selection sort --- sorting/selection.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 sorting/selection.py diff --git a/sorting/selection.py b/sorting/selection.py new file mode 100644 index 0000000..20b27d8 --- /dev/null +++ b/sorting/selection.py @@ -0,0 +1,15 @@ +def selection(array): + size = len(array) + for i in range(size-1): + least = array[i] + count = i + for j in range(i+1, size): + if least > array[j]: + least = array[j] + count = j + + temp = array[i] + array[i] = array[count] + array[count] = temp + + return array