Question: 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:

Need help completing QuickSort function which calls my partiton function getting wrong

REFERENCE code:

output; input file contains "AbracadaBra" OUTPUT should be: 10 7 0 3

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

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!