From eff43f4c4e2446f652ab87be1d4baeb02e3571f5 Mon Sep 17 00:00:00 2001 From: pkbharti Date: Mon, 29 Oct 2018 20:36:51 +0530 Subject: [PATCH] Added selection sort --- sorting/selection.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 sorting/selection.py diff --git a/sorting/selection.py b/sorting/selection.py new file mode 100644 index 0000000..e2b228e --- /dev/null +++ b/sorting/selection.py @@ -0,0 +1,18 @@ + +def selection(sort_list): + for j in range(len(sort_list)): + smallest_element = min(sort_list[j:]) + index = sort_list.index(smallest_element) + sort_list[j], sort_list[index] = sort_list[index], sort_list[j] + print('\n\nThe sorted list: \t', sort_list) + print('\n') + + +array_list = [] +size = int(input("Enter size of the list: ")) + +for i in range(size): + elements = int(input("Enter an element: ")) + array_list.append(elements) + +selection(array_list)