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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started