From 42786e73ed4529621c2ae6345e9617918bbae2dc Mon Sep 17 00:00:00 2001 From: SOMIL JAIN <42209500+somiljain7@users.noreply.github.com> Date: Sat, 27 Oct 2018 16:40:31 +0000 Subject: [PATCH] Add files via upload #1 selectionsort --- sorting/selectionsort.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 sorting/selectionsort.py diff --git a/sorting/selectionsort.py b/sorting/selectionsort.py new file mode 100644 index 0000000..3aa3e2a --- /dev/null +++ b/sorting/selectionsort.py @@ -0,0 +1,16 @@ +#selection sorting +import sys +A = [6, 2, 1, 3, 4] +for i in range(len(A)): + + min_index = i + for j in range(i+1, len(A)): + if A[min_index] > A[j]: + min_index = j + + A[i], A[min_index] = A[min_index], A[i] + +print ("Sorted array") +for i in range(len(A)): + print("%d" %A[i]) +