From f49b7145f77d481ed375bf1d8f176cabcd84ecd9 Mon Sep 17 00:00:00 2001 From: Arju Aman <33257286+arjuaman@users.noreply.github.com> Date: Sun, 23 Aug 2020 12:32:26 +0530 Subject: [PATCH 1/2] Selection sort --- Basic-Scripts/selection_sort.py | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 Basic-Scripts/selection_sort.py diff --git a/Basic-Scripts/selection_sort.py b/Basic-Scripts/selection_sort.py new file mode 100644 index 00000000..e1362d74 --- /dev/null +++ b/Basic-Scripts/selection_sort.py @@ -0,0 +1,11 @@ +def selecsort(lst): + for i in range(len(lst)): + minpos=i + for j in range(i,len(lst)): + if lst[j] Date: Mon, 24 Aug 2020 21:14:30 +0530 Subject: [PATCH 2/2] Added docstring and it now takes input from user --- Basic-Scripts/selection_sort.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/Basic-Scripts/selection_sort.py b/Basic-Scripts/selection_sort.py index e1362d74..cd9372b6 100644 --- a/Basic-Scripts/selection_sort.py +++ b/Basic-Scripts/selection_sort.py @@ -1,4 +1,5 @@ def selecsort(lst): + ''' It takes a list as input from the user and returns it's sorted version. ''' for i in range(len(lst)): minpos=i for j in range(i,len(lst)): @@ -6,6 +7,13 @@ def selecsort(lst): minpos=j (lst[i],lst[minpos])=(lst[minpos],lst[i]) - for item in lst: - print(item) -selecsort([1,5,87,2,-56,89]) + return lst; + +n = int(input("Enter the number of elements to sort: ")) +input_list = [] +for element in range(0,n): + cin = int(input("Enter the element: ")) + input_list.append(cin) + +sorted_list = selecsort(input_list) +print(sorted_list)