From d3c43d03eeaf62f3cb5550d10fe7c1d26cecbb41 Mon Sep 17 00:00:00 2001 From: Visakhsebastian <37535440+Visakhsebastian@users.noreply.github.com> Date: Sun, 2 Oct 2022 17:46:11 +0530 Subject: [PATCH] Add files via upload --- Sorting/selection_sort.py.txt | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 Sorting/selection_sort.py.txt diff --git a/Sorting/selection_sort.py.txt b/Sorting/selection_sort.py.txt new file mode 100644 index 0000000..9ced992 --- /dev/null +++ b/Sorting/selection_sort.py.txt @@ -0,0 +1,18 @@ + +def selectionSort(array, size): + + for ind in range(size): + min_index = ind + + for j in range(ind + 1, size): + # select the minimum element in every iteration + if array[j] < array[min_index]: + min_index = j + # swapping the elements to sort the array + (array[ind], array[min_index]) = (array[min_index], array[ind]) + +arr = [-2, 45, 0, 11, -9,88,-97,-202,747] +size = len(arr) +selectionSort(arr, size) +print('The array after sorting in Ascending Order by selection sort is:') +print(arr)