I am having trouble applying the insertion sort algorithm to the string because it. I have been getting various errors which I think are from issues regarding strings vs char types.
Ex:
candidate template ignored: could not match 'stack' against 'basic_string'
operator> (const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y)
The insertion sort algorithm was pulled from geeks for geeks but I just changed it to string array.
void insertionSort(string arr[], int n)
{
int i, key, j, unsortedness;
for (i = 1; i < n; i++)
{
key = arr[i];
j = i - 1;
/* Move elements of arr[0..i-1], that are
greater than key, to one position ahead
of their current position */
while (j >= 0 && arr[j] > key)
{
arr[j + 1] = arr[j];
j = j - 1;
}
arr[j + 1] = key;
}
}
int main()
{
//Read in from file stuff missing to save space
int d, lengthStrings, numberStrings; // D will hold the number of data sets
infile >> d;
cout << d << endl;
while (d != 0)
{
infile >> lengthStrings;
infile >> numberStrings;
int numCopy = numberStrings;
int i = 0;
string arrayDna[numberStrings]; //char arrayDna[numberStrings][lengthStrings] instead?;
while (numberStrings != 0)
{
infile >> arrayDna[i];
i++;
numberStrings--;
}
insertionSort(arrayDna[], numCopy);
for (int i = 0; i < numCopy; i++)
cout << arrayDna[i] << "\n";
d--;
So basically I need help fixing the error not allowing me to apply this insertion algorithm to my own string array.