Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Radix Sort

 
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!
 
Marshal
Posts: 25682
69
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!
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
 
Paul Clapham
Marshal
Posts: 25682
69
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?
 
Bartender
Posts: 612
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!
 
It sure was nice of your sister to lend us her car. Let's show our appreciation by sharing this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic