程序代写代做代考 algorithm CMPSC-132: Programming and Computation II

CMPSC-132: Programming and Computation II

Fall 2018

Lab #12
Due Date: 11/18/2018, 11:59PM

Instructions:

– The work in this lab must be completed alone and must be your own. Do not copy code
from online sources. That is considered plagiarism.

– Use the starter code provided on this CANVAS assignment. Do not change the function
names or given started code on your script

– The file name must be LAB12.py (incorrect name files will get a -1 point deduction)

– A doctest is provided as an example of code functionality. Getting the same result as
the doctest does not guarantee full credit. You are responsible for testing your code

with enough data as possible.

– Each function must return the output (Do not use print in your final submission otherwise,
you will get a -1 pt deduction)

– Do not include test code outside any function in the upload. Remove all your testing code
before uploading your file. Do not include the input() function in your submission.

Goal:
[10 pts] As discussed in class, bubble sort is a simple sorting algorithm that works by repeatedly

stepping through the list to be sorted, comparing each pair of adjacent items and swapping them if

they are in the wrong order. The pass through the list is repeated until no swaps are needed, which

indicates that the list is sorted. Write the function bubbleSort(numList) that takes an unsorted list

of numbers and uses the bubble sort algorithm to return the sorted list. The function should also

returns a dictionary with the state of the list after each complete pass.

– You are not allowed to use the sorted() method or the sort operator. Your code will not get
credit if you use them

EXAMPLES:

>>> bubbleSort([2,3,5,4,1])

({1: [2, 3, 4, 1, 5], 2: [2, 3, 1, 4, 5], 3: [2, 1, 3, 4, 5], 4: [1, 2,
3, 4, 5]}, [1, 2, 3, 4, 5])

Second returned value, the sorted list

This is another valid output:
>>> bubbleSort([2,3,5,4,1])

({1: [2, 3, 4, 1, 5], 2: [2, 3, 1, 4, 5], 3: [2, 1, 3, 4, 5], 4: [1, 2,

3, 4, 5]}, 5: [1, 2, 3, 4, 5]}, [1, 2, 3, 4, 5])

Second returned value, the sorted list

Deliverables:

 Submit your code in a file name LAB12.py to the Lab12 CANVAS assignment before the

due date