From 191f94cd5ff7b6c736bbc0e31efc5f842bff0ab3 Mon Sep 17 00:00:00 2001 From: Yakshu Makkar <53832153+YAKSHUMAKKAR39@users.noreply.github.com> Date: Sun, 3 Oct 2021 23:07:05 +0530 Subject: [PATCH] Create Selectionsort.py --- Selectionsort.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Selectionsort.py diff --git a/Selectionsort.py b/Selectionsort.py new file mode 100644 index 0000000..d2462ff --- /dev/null +++ b/Selectionsort.py @@ -0,0 +1,21 @@ +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]),