Apr-24-2018, 06:54 PM
Quote:1-Yes, you're right, that function was the bubble sort recursive function.bubblesortOnePass()
's return value is never used, so you don't need to returnl
.
Then i modified it and i transformed it into another non recursive function with only one pass.
So i must remove that condition.
Quote:2- Is it good to define a localI did in this way because the variable counter inside the function is "hooked" at the counter variable outside the function.counter
in line 50, then a globalcounter
in line 17?
And every time the recursive function restarts, that variable doesn't come back to zero.
It comes back to zero only when the step of loop outside the function ends and a new step starts.
But i've been coding only for 4 months, so i'm not sure this is an elegant solution.
Quote:5- If I had to guess, the problem might be line 29.
mmm.... if i write this list for example:
new = [9,2,8,1,7]and i pass it to the bubblesortTwoPass function in this way:
after2pass = bubblesortTwopass(new) print(after2pass)
Output:[2,1,7,8,9]
So the algorithm is right.But i don't understand why if i write:
bubblesortTwopass(new) print(new)the output is
Output:[2,8,1,7,9]
in other words i obtain the bubble sort after only the first pass without the second.