-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbubblesortalpha.py
More file actions
22 lines (19 loc) · 831 Bytes
/
Copy pathbubblesortalpha.py
File metadata and controls
22 lines (19 loc) · 831 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#Creating list of alphabets
list =['q','w','e','r','t','y','g','h','j','k','l','u','i','o','p','a','s','d','f','g','h','m','n','b','c','x','z','v']
print ("initial List :", list) #print initial list (unsorted)
#creating function of Bubble sort
def bubbleSort(list):
l = len(list)
print ('lenght of list : ', l)
for i in range(0, l-1):
for j in range(l-1-i): # for loop to get value of 1 and 2 element to compare
if list[j] > list[j+1]: # comaprision
temp = list[j] #swapping of 2nd element to left if its bigger (swapping via third variable)
list[j] = list[j+1]
list[j+1] = temp
#calling function
bubbleSort(list)
'''for i in range(len(list)):'''
#print sorted list
print ('Sorted list : ', list)
#Task Completed