I was looking for the newer version. The answer needs to be in python 3.x.....Th
ID: 3710439 • Letter: I
Question
I was looking for the newer version. The answer needs to be in python 3.x.....The Question is, There is a simple, but inef?cient, algorithm, called bubble-sort, for sorting a list L of n comparable elements. This algorithm scans the list n?1 times, where, in each scan, the algorithm compares the current element with the next one and swaps them if they are out of order. Implement a bubble sort function that takes a positional list L as a parameter. What is the running time of this algorithm, assuming the positional list is implemented with a doubly linked list?
Explanation / Answer
////////////////////////bubblesort.py////////////////////////
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
list = []
print("Please Enter the size of the list:")
size = input()
listsize = int(size)
print("Please Enter the elements of the list line by line:")
for i in range(0,listsize):
value = input()
listvalue = int(value)
list.append(listvalue)
bubbleSort(list)
print(list)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.