From 0600bd3683fdeb7c2528c1a2e9f819a257227ade Mon Sep 17 00:00:00 2001 From: Saksham Raj <87775820+sakshamraj999@users.noreply.github.com> Date: Fri, 22 Oct 2021 18:04:16 +0530 Subject: [PATCH] Add files via upload Selection Sort Algorithm --- selection_sort.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 selection_sort.py diff --git a/selection_sort.py b/selection_sort.py new file mode 100644 index 0000000..f315490 --- /dev/null +++ b/selection_sort.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]),