| | |
radix sort
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jun 2004
Posts: 10
Reputation:
Solved Threads: 2
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
If you want here you are my own queue class
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
C++ Syntax (Toggle Plain Text)
#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(); } } }
•
•
Join Date: May 2004
Posts: 82
Reputation:
Solved Threads: 4
•
•
•
•
Originally Posted by ching
can anyone give me a example of a radix sort
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 243First, 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 536Then, sort them by the next most significant digit (tens):
403 423 234 536 243 171 586 92Now 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
#6 32 Days Ago
![]() |
Similar Threads
- Radix Sort Code (C++)
- C++ Radix Sort - Bitshift Operators (C++)
- radix sort using queue and linked list (C++)
Other Threads in the C++ Forum
- Previous Thread: compile pthreads in windows netbeans
- Next Thread: Radix Sort Code
| Thread Tools | Search this Thread |
api array beginner binary bitmap c++ c/c++ calculator char class classes code coding compile compiler console conversion convert count data database delete desktop developer directshow dll download dynamic email encryption error file forms fstream function functions game getline givemetehcodez google graph gui homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux loop looping loops map math matrix memory multiple news node number output parameter pointer problem program programming project proxy python read recursion recursive return sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






