From ac8be74b7187a32c8162454fac0963ead41ed4d0 Mon Sep 17 00:00:00 2001 From: Moh Aarif Ahmed Date: Thu, 1 Oct 2020 11:40:52 +0530 Subject: [PATCH] Created Selection_Sort.txt Created selection_sort.txt file and added code for selection sort algorithm --- code/12-sorting-algorithm/Selection_Sort.txt | 23 ++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 code/12-sorting-algorithm/Selection_Sort.txt diff --git a/code/12-sorting-algorithm/Selection_Sort.txt b/code/12-sorting-algorithm/Selection_Sort.txt new file mode 100644 index 0000000..456b7bf --- /dev/null +++ b/code/12-sorting-algorithm/Selection_Sort.txt @@ -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]), \ No newline at end of file