I want to modify this Radix sort C++ to work with strings only. I want to sort words not numbers. I don't know what to change or where to change it. Any suggestions?
// CS 9F
// March 3, 2012
// Include files
#include <iostream> // used for cin, cout
#include <conio.h>
#include <fstream> // file input/output
#include <queue> // class for queue's
#include <string> // used for string's
using namespace std;
// Global Type Declarations
typedef queue<string> Q;
// Function Prototypes
void instruct(void);
void pause ();
int main()
{
// Declaration section
Q holder, tempholder, sorter[10];
const char Digits = 10; // Number of digits per item
char numInput[Digits]; // Stores data input
int bin; // Stores digits of queue
int run1; // Records runs for print
int run2; // Records runs for print
// Executable section
instruct ();
cout << "Inserting Data In The Queue\n" ;
cout << "----------------------------\n" << endl;
ifstream inDataFile( "radixdata.txt", ios::in); //Open Data File
if ( !inDataFile )
{
cerr << "File could not be opened\n";
exit(1);
}
inDataFile >> numInput; //Read In Data
while ( !inDataFile.eof()) //Stop When End Of File Reached
{
holder.push(numInput); //Put Data In Queue
inDataFile >> numInput; //Read In Next Line Of Data
}
run1 = 0;
tempholder = holder; //Copy holder queue to tempholder
cout << "Data In The Queue\n\n";
while (!tempholder.empty())
{ //Print Out Unsorted Queue
cout << tempholder.front() << " ";
tempholder.pop();
run1++;
if ( run1 % 10 == 0 )
cout <<endl;
}
cout << "\n\nBeginning Sort Of The Queue" << endl;
cout << "----------------------------" << endl;
pause();
for ( int i = Digits - 1; i > - 1; i-- ) //Begin Sort Of Queue Using Sorter
{
while (!holder.empty())
{
bin = (static_cast<char>(holder.front().at(i))) - 48;
sorter[bin].push(holder.front());
holder.pop();
}
for ( int j = 0; j <= 9; j++ )
{
while (!sorter[j].empty()) //Run Through Sorter
{
holder.push(sorter[j].front());//Push Front Digit From Holder
sorter[j].pop();} //Pop Out From Sorter
}
}
run2 = 0;
cout << "Data In The Sorted Queue\n\n";
while (!holder.empty())
{ //Print Out Sorted Queue
cout << holder.front() << " ";
holder.pop();
run2++;
if ( run2 % 10 == 0 )
cout <<endl;
}
pause();
return 0;
}
void instruct (void)
{
// Declaration section
// Executable section
cout << "\t************************************************************"<< endl;
cout << "\t* This program will read an input file named radixdata.txt,*"<< endl;
cout << "\t* which contains a list of words *"<< endl;
cout << "\t* The computer will use this input and perform a *"<< endl;
cout << "\t* radix sort of the words using the queue class. The *"<< endl;
cout << "\t* results of the sort will then be printed to the screen. *"<< endl;
cout << "\t************************************************************"<< endl;
cout << endl;
}
void pause ()
{
// Declaration section
// Executable section
cout << "\nPress any key to continue...";
getch();
cout << "\r";
cout << " ";
cout << "\r";
}