From 686cf0f3e594e8c2f8e13aca9036a428bfafdc15 Mon Sep 17 00:00:00 2001 From: RICHA BHARTI <50147461+richabh456@users.noreply.github.com> Date: Wed, 16 Oct 2019 23:12:32 +0530 Subject: [PATCH] Create selectionsort.py fixed #446 --- selection_sort/python/selectionsort.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 selection_sort/python/selectionsort.py diff --git a/selection_sort/python/selectionsort.py b/selection_sort/python/selectionsort.py new file mode 100644 index 00000000..b95cc11f --- /dev/null +++ b/selection_sort/python/selectionsort.py @@ -0,0 +1,23 @@ +# Python program for implementation of Selection +# Sort +import sys +A = [64, 25, 12, 22, 11] + +# Traverse through all array elements +for i in range(len(A)): + + # Find the minimum element in remaining + # unsorted array + min_idx = i + for j in range(i+1, len(A)): + if A[min_idx] > A[j]: + min_idx = j + + # Swap the found minimum element with + # the first element + A[i], A[min_idx] = A[min_idx], A[i] + +# Driver code to test above +print ("Sorted array") +for i in range(len(A)): + print("%d" %A[i]),