Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need help completing QuickSort function which calls my partiton function getting wrong output; input file contains AbracadaBra OUTPUT should be: 10 7 0 3 5

Need help completing QuickSort function which calls my partiton function

getting wrong output;

input file contains "AbracadaBra"

OUTPUT should be:

10 7 0 3 5 8 1 4 6 9 2

Need to do:

image text in transcribed

REFERENCE code:

image text in transcribed

---------------------------------------------------------

my code so far:

#include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std;

void readFromFile(string &S, string filename); void convertToLower(string &S); bool lessThan(const string &S, int first, int second, int pass); int partition(const string &S, vector &indices, int low, int high); int quicksort(const string &S, vector &indices,int low, int high);

int main(int argc, char *argv[]) { string S; string filename = argv[1]; vector index; readFromFile(S,filename); convertToLower(S); if (argc == 2) { cout

quicksort(S,index,low,high); for(int k=0; k

cout

void readFromFile(string &S, string filename) { string buffer; ifstream ifile; ifile.open(filename);

while (getline(ifile, buffer, ' ')) { string Stemp; Stemp = buffer; S = S+Stemp; } } void convertToLower(string &S) { transform(S.begin(), S.end(), S.begin(), ::tolower); }

int partition(const string &S, vector &indices, int low, int high) { int i=low; int j=high-1; int pivot = high;

while (i=low && lessThan(S,indices[j] ,pivot, 0) == false ){

j--; }

if(i

} swap(indices[high],indices[i]); return i; }

bool lessThan(const string &S, int first, int second , int pass) {

if(S[first] S[second]){ return false; } else //return T OR F return lessThan(S, first+1, second+1,0);

}

int quicksort(const string &S,vector &indices, int low, int high) { if(low

} }

Input parameters 1. Constant string S by reference 2. Vector of integers indices holding indices of suffixes of S 3. Integer low, the lowest index in the range 4. Integer high, the highest index in the range Output: Use cout to print out the indices from the vector indices in this format: index QuickSort must sort suffixes of the input string S in alphabetical order Instead of storing each suffix separately, and swapping suffixes (strings), it will access suffixes of S indirectly via indices that are stored in indices. The indices of suffixes represent the starting positions of suffixes in S void quicksort (vector &A, int low, int high)( if (low &A, int low, int high) int pivot A[high]; int i low, j high - 1; while(i low && A[j] > pivot) if(i QuickSort must sort suffixes of the input string S in alphabetical order Instead of storing each suffix separately, and swapping suffixes (strings), it will access suffixes of S indirectly via indices that are stored in indices. The indices of suffixes represent the starting positions of suffixes in S void quicksort (vector &A, int low, int high)( if (low &A, int low, int high) int pivot A[high]; int i low, j high - 1; while(i low && A[j] > pivot) if(i

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Database Technology Edbt 88 International Conference On Extending Database Technology Venice Italy March 14 18 1988 Proceedings Lncs 303

Authors: Joachim W. Schmidt ,Stefano Ceri ,Michele Missikoff

1988th Edition

3540190740, 978-3540190745

More Books

Students also viewed these Databases questions

Question

e. Compute P(0.25 Answered: 1 week ago

Answered: 1 week ago

Question

Understand the different approaches to job design. page 167

Answered: 1 week ago