Not Yet Answered # radix sort

abu_sager abu_sager gusano79 247 Champhero -1 ithelp 757 Write a C program that should create a 10 element array of random integers (0 to 9). The program should total all of the numbers in the odd positions of the array and compare them with the total of the numbers in the even positions of the array and indicate ...

1

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

```
#include <iostream>
using std::cin;
using std::cout;
using std::endl;
#include <cstdlib>
#include <ctime>
#include "queue.h"
#define MAX 11
void CopyToLast(Queue<int> []);
int main()
{
Queue<int> q[MAX];
srand(time(0));
int res,i,j,digit = 4,passHelper=10,temp,pos;
cout << "Before Sorting : \n";
for(i=0;i<100;i++) {
res = rand() % 10000;
cout << res << "|";
q[MAX-1].append(res);
}
for(i=0;i<digit;i++) {
while(!q[MAX-1].empty()) {
q[MAX-1].retrieve(temp);
q[MAX-1].serve();
pos=temp;
for(j=0;j<i;j++)
pos/=10;
pos %= 10;
q[pos].append(temp);
}
passHelper *= 10;
CopyToLast(q);
}
cout << "\nAfter sorting :\n";
while(!q[MAX-1].empty()) {
q[MAX-1].retrieve(temp);
cout << temp << "|";
q[MAX-1].serve();
}
return 0;
}
void CopyToLast(Queue<int> g[])
{
int i,temp;
for(i=0;i<MAX-1;i++) {
while(!g[i].empty()) {
g[i].retrieve(temp);
g[MAX-1].append(temp);
g[i].serve();
}
}
}
```

If you want here you are my own queue class

0

This program is generates 100 random integers and store them in the latest Queue then start sorting

1

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.

0

Can anyone provide me the Radix sorting through other than the Queue.w8ng for the replyyyyyy......

0

Can anyone provide me the Radix sorting through other than the Queue.w8ng for the replyyyyyy......

You can use buckets to code radix sort.

This article has been dead for over six months. Start a new discussion instead.

Recommended Articles

the function that I created to find the ...

Hi. so this is actually a continuation from another question of mineHere but i was advised to start a new thread as the original question was already answered.

This is the result of previous question answered :

code for the listbox - datagridview interaction

At the top of the code ...