Python Forum
Bubble sort quiz: why the result is not the same?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Bubble sort quiz: why the result is not the same?
#4
Quote:1- bubblesortOnePass()'s return value is never used, so you don't need to return l.
Yes, you're right, that function was the bubble sort recursive function.
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 local counter in line 50, then a global counter in line 17?
I did in this way because the variable counter inside the function is "hooked" at the counter variable outside the function.
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.
Reply


Messages In This Thread
RE: Bubble sort quiz: why the result is not the same? - by lupoalberto - Apr-24-2018, 06:54 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  QUIZ GUI Form_When admin panel is open, main quiz form is getting freeze Uday 4 809 Aug-25-2023, 08:24 PM
Last Post: deanhystad
Photo a.sort() == b.sort() all the time 3lnyn0 1 1,368 Apr-19-2022, 06:50 PM
Last Post: Gribouillis
  Python Networkx: Visualize an edge weight with a bubble/circle uvw 0 2,046 Sep-01-2021, 06:26 AM
Last Post: uvw
  Bubble sort on randomized integers bellevie 4 5,413 May-16-2017, 05:28 PM
Last Post: bellevie

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020