I need a radix sort using queues in c++ in order to sort strings alphabeticall y
ID: 3640261 • Letter: I
Question
I need a radix sort using queues in c++ in order to sort strings alphabetically.
It should read in a file
words.txt containing:
zion
charlie
alpha
betta
michael
john
smith
and should write to another file wordsout.txt
with all words sorted alphabetically as follows:
alpha
betta
charlie
john
michael
smith
zion
Again it should use QUEUES that sorts STRINGS with RADIX SORT in C++
This is what I already have, but don't know how to change it for strings:
// Include files
#include // used for cin, cout
#include
#include // file input/output
#include // class for queue's
#include // used for string's
using namespace std;
// Global Type Declarations
typedef queue Q;
// Function Prototypes
void pause ();
int main()
{
// Declaration section
Q holder, tempholder, sorter[10];
const int Digits = 6; // 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 " ;
cout << "---------------------------- " << endl;
ifstream inDataFile( "radixdata.txt", ios::in); //Open Data File
if ( !inDataFile )
{
cerr << "File could not be opened ";
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 ";
while (!tempholder.empty())
{ //Print Out Unsorted Queue
cout << tempholder.front() << " ";
tempholder.pop();
run1++;
if ( run1 % 10 == 0 )
cout <}
cout << " Beginning 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(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 ";
while (!holder.empty())
{ //Print Out Sorted Queue
cout << holder.front() << " ";
holder.pop();
run2++;
if ( run2 % 10 == 0 )
cout <}
pause();
return 0;
}
void pause ()
{
// Declaration section
// Executable section
cout << " Press any key to continue...";
getch();
cout << " ";
cout << " ";
cout << " ";
}
**************************************…
HELP ME MODIFY THIS CODY OR HELP ME WITH NEW CODE.
Thank You
Explanation / Answer
const int numblocks = 256; void radixSort(String rsarr[],int length, int offset = 0) { int inplace = 0; vector blocks[numblocks]; //split the strings into bins for (int i=0;iRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.