Question: Using Python please show how to time a bubble sort such as presented below: def bubbleSort(list): needNextPass = True k = 1 while k <

Using Python please show how to time a bubble sort such as presented below:

def bubbleSort(list):

needNextPass = True k = 1 while k < len(list) and needNextPass: # List may be sorted and next pass not needed needNextPass = False for i in range(len(list) - k): if list[i] > list[i + 1]: # swap list[i] with list[i + 1] temp = list[i] list[i] = list[i + 1] list[i + 1] = temp needNextPass = True # Next pass still needed

# A test method def main(): list = [5000, 200000, 250000, 10000, 150000, 300000] bubbleSort(list) for v in list: print(v, end = ",")

main()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!