Bubble sort, descending
Task
Write a function zorad_zostupne(zoznam) that sorts the list in place (changes it) from the largest to the smallest item using bubble sort, and returns how many swaps it made. Swap neighbours only when the left one is smaller than the right one - equal items are not swapped.
Do not use sort or sorted. For z = [3, 1, 2] the call zorad_zostupne(z) returns 1 and z becomes [3, 2, 1].
Examples
Call
z = [3, 1, 2] v = zorad_zostupne(z) print(z, v)
Expected output
[3, 2, 1] 1
Rules
Write the bubble sort - no
sortorsorted.
After you submit, 7 hidden tests will also check your solution: already sorted descending, sorted ascending, equal items in place, equal items to move, an empty list, one item, mixed numbers.
You need to know
Python starts the first time you run code.
Ctrl+Enter runs the program. Tab indents. Press Esc, then Tab, to leave the editor.
Input (stdin)
Each line = one call to input().
Output
Hints
Try it yourself first. Each hint reveals a little more - and lowers the reward a little.
Signed out, hints are free - but no XP is awarded either.
Solution
The solution unlocks after the last hint.