From 071acaae960275d19589cd326e7fbb4976da1471 Mon Sep 17 00:00:00 2001 From: Fahad Patel <42268318+fahad1403@users.noreply.github.com> Date: Thu, 1 Oct 2020 00:35:34 +0530 Subject: [PATCH 1/2] Update BubbleSort.py --- BubbleSort.py | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/BubbleSort.py b/BubbleSort.py index 223639a..0ca059e 100644 --- a/BubbleSort.py +++ b/BubbleSort.py @@ -1,20 +1,16 @@ -n1=int(input("Enter Number 1:- ")) -n2=int(input("Enter Number 2:- ")) -n3=int(input("Enter Number 3:- ")) -n4=int(input("Enter Number 4:- ")) -n5=int(input("Enter Number 5:- ")) -n6=int(input("Enter Number 6:- ")) -n7=int(input("Enter Number 7:- ")) -n8=int(input("Enter Number 8:- ")) -n9=int(input("Enter Number 9:- ")) -n10=int(input("Enter Number 10:- ")) - -a= [n1,n2,n3,n4,n5,n6,n7,n8,n9,n10] -count=0 -for i in range(len(a)): - for j in range(1,len(a)): - if a[j-1] > a[j]: - count+=1 - a[j-1],a[j]= a[j], a[j-1] -print(a) -print(f"The Total No. of times it was Swapped is {count}") +def bubble_sort(sort_list): + for j in range(len(sort_list)): + for k in range(len(sort_list) - 1): + if sort_list[k] > sort_list[k + 1]: + sort_list[k], sort_list[k + 1] = sort_list[k + 1], sort_list[k] + print(sort_list) + + +lst = [] +size = int(input("Enter size of the list: \t")) + +for i in range(size): + elements = int(input("Enter the element: \t")) + lst.append(elements) + +bubble_sort(lst) From cc5d915ee300da1eb26421479fc39120fbc44440 Mon Sep 17 00:00:00 2001 From: Fahad Patel <42268318+fahad1403@users.noreply.github.com> Date: Thu, 1 Oct 2020 00:37:43 +0530 Subject: [PATCH 2/2] Update README.md Added code and updated Readme to take user input for Bubble sort in python. Earlier this program didn't used to take user input, But now it is possible. I have made the required changes --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index d7d492a..3cf8bb7 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,8 @@ This is a Simple Algorithm in Python Language which will Sort the given Numbers in assending order. -You have to give Number before running the program. +This Program takes user input for all the numbers that need to be sorted -This program does not takes User Input.