radix sort

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Jun 2004
Posts: 6
Reputation: ching is an unknown quantity at this point 
Solved Threads: 0
ching ching is offline Offline
Newbie Poster

radix sort

 
1
  #1
Jun 8th, 2004
can anyone give me a example of a radix sort
there are 10 kinds of people those who understand binary and ...
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 10
Reputation: abu_sager is an unknown quantity at this point 
Solved Threads: 2
abu_sager abu_sager is offline Offline
Newbie Poster

Re: radix sort

 
1
  #2
Jun 9th, 2004
Hello,
I have done the Radix with queue
here you are an example
But the queue is my own Queue

retrieve: return the first element
serve : delete the first element;
dequeue: insertlast

  1. #include <iostream>
  2. using std::cin;
  3. using std::cout;
  4. using std::endl;
  5. #include <cstdlib>
  6. #include <ctime>
  7. #include "queue.h"
  8. #define MAX 11
  9. void CopyToLast(Queue<int> []);
  10. int main()
  11. {
  12. Queue<int> q[MAX];
  13. srand(time(0));
  14. int res,i,j,digit = 4,passHelper=10,temp,pos;
  15. cout << "Before Sorting : \n";
  16. for(i=0;i<100;i++) {
  17. res = rand() % 10000;
  18. cout << res << "|";
  19. q[MAX-1].append(res);
  20.  
  21. }
  22.  
  23. for(i=0;i<digit;i++) {
  24.  
  25. while(!q[MAX-1].empty()) {
  26. q[MAX-1].retrieve(temp);
  27. q[MAX-1].serve();
  28. pos=temp;
  29. for(j=0;j<i;j++)
  30. pos/=10;
  31. pos %= 10;
  32. q[pos].append(temp);
  33. }
  34.  
  35.  
  36. passHelper *= 10;
  37. CopyToLast(q);
  38. }
  39.  
  40. cout << "\nAfter sorting :\n";
  41. while(!q[MAX-1].empty()) {
  42. q[MAX-1].retrieve(temp);
  43. cout << temp << "|";
  44. q[MAX-1].serve();
  45. }
  46.  
  47. return 0;
  48. }
  49. void CopyToLast(Queue<int> g[])
  50. {
  51. int i,temp;
  52. for(i=0;i<MAX-1;i++) {
  53. while(!g[i].empty()) {
  54. g[i].retrieve(temp);
  55. g[MAX-1].append(temp);
  56. g[i].serve();
  57. }
  58. }
  59.  
  60. }
If you want here you are my own queue class
Attached Files
File Type: h Queue.h (2.6 KB, 81 views)
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 10
Reputation: abu_sager is an unknown quantity at this point 
Solved Threads: 2
abu_sager abu_sager is offline Offline
Newbie Poster

Re: radix sort

 
0
  #3
Jun 9th, 2004
This program is generates 100 random integers and store them in the latest Queue then start sorting
Reply With Quote Quick reply to this message  
Join Date: May 2004
Posts: 82
Reputation: gusano79 is on a distinguished road 
Solved Threads: 4
gusano79 gusano79 is offline Offline
Junior Poster in Training

Re: radix sort

 
1
  #4
Jun 10th, 2004
Originally Posted by ching
can anyone give me a example of a radix sort
Here's an explanation to complement Abu's code example:

A radix sort works with the digits of a number, working from the least significant digit to the most. Here's a sample set of numbers:
423 586 403 171 92 536 234 243
First, sort the numbers by the least siginificant digit (ones). For this algorithm to work, your buckets have to be order-preserving.
171 92 423 403 243 234 586 536
Then, sort them by the next most significant digit (tens):
403 423 234 536 243 171 586 92
Now hundreds:
92 171 234 243 403 423 536 586
...and they're sorted. Each step doesn't have to be a bucket sort; any order-preserving sort will work.
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 1
Reputation: Champhero is an unknown quantity at this point 
Solved Threads: 0
Champhero Champhero is offline Offline
Newbie Poster
 
0
  #5
32 Days Ago
Can anyone provide me the Radix sorting through other than the Queue.w8ng for the replyyyyyy......
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 1,827
Reputation: ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all 
Solved Threads: 118
ithelp's Avatar
ithelp ithelp is offline Offline
Posting Virtuoso
 
0
  #6
32 Days Ago
Originally Posted by Champhero View Post
Can anyone provide me the Radix sorting through other than the Queue.w8ng for the replyyyyyy......
You can use buckets to code radix sort.
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 2
Reputation: dibilasd is an unknown quantity at this point 
Solved Threads: 0
dibilasd dibilasd is offline Offline
Newbie Poster
 
0
  #7
29 Days Ago
dibilu
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC