Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

DATABASE Administrator Make A Difference

Authors: Mohciine Elmourabit

1st Edition

B0CGM7XG75, 978-1722657802

More Books

Students also viewed these Databases questions

Question

What is the function of a statement of owners equity?

Answered: 1 week ago