Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions BubbleSort.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#Bubble Sort Program implementation in Python, where the List is input by the user during the runtime.
#This code is Contributed by Reejo.


def Bubblesort(l,n): #BubbleSort function
for i in range(0,n):
for j in range(0,n-i-1):
if l[j]>l[j+1]:
l[j],l[j+1]=l[j+1],l[j]




n=int(input("Enter the Number of Elements to Insert:-"))

l=[ ] #Creating a list

print("\n----Enter the Elements of the List----\n")
for i in range(0,n): #Inserting the Elements of the List.
print("Enter ",i+1," Element:-",end="")
temp=int(input())
l.append(temp)

print("Before BubbleSorting the List is:-")
print(l)

Bubblesort(l,n) #Calling bubble sort.
print("After BubbleSorting the List is:-")
print(l)