From 22662965beaf9888a4cfbdd13c4516546fcb9e29 Mon Sep 17 00:00:00 2001 From: divya116 <56511764+divya116@users.noreply.github.com> Date: Wed, 16 Oct 2019 11:16:30 +0530 Subject: [PATCH] selection_sort.py Added selection sort code in python --- Algorithms/sorting/Selection Sort Python | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 Algorithms/sorting/Selection Sort Python diff --git a/Algorithms/sorting/Selection Sort Python b/Algorithms/sorting/Selection Sort Python new file mode 100644 index 0000000..2308c8c --- /dev/null +++ b/Algorithms/sorting/Selection Sort Python @@ -0,0 +1,17 @@ +import sys +A = [64, 25, 12, 22, 11] + +for i in range(len(A)): + + min_idx = i + for j in range(i+1, len(A)): + if A[min_idx] > A[j]: + min_idx = j + + + A[i], A[min_idx] = A[min_idx], A[i] + + +print ("Sorted array") +for i in range(len(A)): + print("%d" %A[i]),