I'm trying to implement the quicksort on a string of characters. The output should give me an alphabetical order version of the input, however right now it's just giving me the original input. This was an attempt trying to translate the pseudo code from Intro to Algorithm 3rd edition on Quicksort.
Any help would be greatly appreciated, thanks!
Here's the pseudo code of quicksort from the book
#include <string>
#include <iostream>
#include <stdlib.h>
using namespace std;
int partition_str(string A, int start, int finish){
char x = A[finish], temp;
int i = start - 1;
for (int j = start; j <= finish -1; j++){
if (A[j] <= x){
i ++;
temp = A[i]; A[i] = A[j]; A[j] = temp;
}
temp = A[i+1]; A[i+1] = A[finish]; A[finish] = temp;
return i+1;
}
}
string quicksort_char(string A, int start, int finish)
{
if (start < finish)
{
start = partition_str(A, start, finish);
quicksort_char(A, start, finish -1);
quicksort_char(A, start+1, finish);
}
return A;
}
int main(){
string test = "gsgkdsdkjs";
string result = quicksort_char(test, 0, 10);
cout << result << endl;
return 0;
}