This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Radix Sort

 
Ronald Spina
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,

I have just finished implementing my radix sort. Seems to be working fine within the first and second pass, but not in the third and fourth pass. Anyone could please find what i am doing wrong!
Please help me cause i really want to make this Radix Sort work!! I think I have some bugs in my program but I cant find where!!


 
Ronald Spina
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is the output of the program.
Please enter the size of the array. 5
306, 392, 374, 493, 31,
31, 392, 493, 374, 306,
306, 31, 374, 392, 493,
31, 392, 374, 493, 493,
493, 493, 374, 493, 31,

Process completed.

I notice that numbers are also being duplicated in very pass!
 
Paul Clapham
Sheriff
Pie
Posts: 20757
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd suggest that at line 42 you also output the value of index for debugging purposes.
 
Ronald Spina
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did and hmm there is something strange in the output!

145, 960, 490, 681, 257, 862, 377, 386, 943, 517,
0 960, 1 490, 0 681, 0 862, 0 943, 0 145, 0 386, 0 257, 1 377, 2 517,
0 517, 1 517, 0 943, 0 257, 1 257, 0 862, 0 377, 1 377, 0 681, 1 386,
0 257, 0 386, 1 377, 2 386, 0 517, 1 517, 0 681, 1 681, 0 862, 0 943,
0 943, 1 681, 2 386, 3 681, 4 257, 5 862, 6 377, 7 386, 8 943, 9 517,

Any suggestions of what happeing!
 
Darryl Burke
Bartender
Posts: 5125
11
Java Netbeans IDE Opera
 
Paul Clapham
Sheriff
Pie
Posts: 20757
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ronald Spina wrote:Any suggestions of what happeing!


Let's ask that differently: Why does index keep getting set back to zero?
 
Steve Fahlbusch
Bartender
Posts: 602
7
Mac OS X Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and as an extension of what Paul suggested.

you may want to add a print at say line 51 (print out the number, radix and result) just to verify everything is working as you expect.
 
Ronald Spina
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok sorry for posting the same treath to other forums.
I have added some print statements and added some comments.


I have noticed that the index in while loop (47-52) is resetting when passing from a queue to another.
This is the result of my program.
Bdw I made the outer loop to loop I time so I can tackle problem at a time.

Please enter the size of the array. 9
807, 463, 609, 979, 88, 684, 905, 475, 667, 9 ramdom integers stored in numbers. Fine!
807 7, 463 3, 609 9, 979 9, 88 8, 684 4, 905 5, 475 5, 667 7, Finding the LSD and storing them in the queues. Fine!
0 463, 0 684, 0 905, 1 475, 0 807, 1 667, 0 88, 0 609, 1 979, Dequeue the queues on after each other and store int back to numbers. Here is the problem.

Process completed.
 
Ronald Spina
Greenhorn
Posts: 26
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Of course! int index=0; has to be outside the for loop!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic