• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Radix Sort

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Marshal
Posts: 28226
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ronald, please BeForthrightWhenCrossPostingToOtherSites
http://www.java-forums.org/new-java/66538-radix-sort.html

edit: http://www.javaprogrammingforums.com/whats-wrong-my-code/20587-radix-sort.html
 
Paul Clapham
Marshal
Posts: 28226
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Bartender
Posts: 612
7
Mac OS X Python
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Of course! int index=0; has to be outside the for loop!
 
reply
    Bookmark Topic Watch Topic
  • New Topic