Bubble Sorting a List of Python Program.

 Program to Bubble Sorting a List in Python..





Code of Python.

def bubbleSort(alist):
    for passnum in range(len(alist)-1,0,-1):
        for i in range (passnum):
            if alist[i]>alist[i+1]:
                temp=alist[i]
                alist[i]=alist[i+1]
                alist[i+1]=temp
             
alist= []
n=int(input("Enter range of data:"))
for i in range(n):
    alist.append(int(input("Enter an element:")))
bubbleSort(alist)
print("After sorting:",alist)

Output:

Enter range of data:5
Enter an element:54
Enter an element:62
Enter an element:78
Enter an element:15
Enter an element:36
After sorting: [15, 36, 54, 62, 78]

*

إرسال تعليق (0)
أحدث أقدم