From bd493aab97d83c2172d6485d32ee63ad722bd3ee Mon Sep 17 00:00:00 2001 From: Praful Goyal Date: Tue, 2 Oct 2018 12:22:13 +0530 Subject: [PATCH] SelectionSort.py created --- Sorting/Selection Sort/SelectionSort.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 Sorting/Selection Sort/SelectionSort.py diff --git a/Sorting/Selection Sort/SelectionSort.py b/Sorting/Selection Sort/SelectionSort.py new file mode 100644 index 000000000..805a62820 --- /dev/null +++ b/Sorting/Selection Sort/SelectionSort.py @@ -0,0 +1,17 @@ +# Python program for implementation of Selection Sort +# This function takes list as input argument and return sorted list +def SelectionSort(A): +# 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] + return A