Answer:
Following are the method to this question:
void selectionSort(string strArr[], int s) //defining selectionSort method
{
int i,ind; //defining integer variables
string val; //defining string variable
for (i= 0; i< (s-1);i++) //defining loop to count value
{
ind = i; //assign loop value in ind variable
val = strArr[i]; // strore array value in string val variable
for (int j = i+1;j< s;j++) // defining loop to compare value
{
if (strArr[j].compare(val) < 0) //using if block to check value
{
val = strArr[j]; //store value in val variable
ind= j; //change index value
}
}
strArr[ind] = strArr[i]; //assign string value in strArray
strArr[i] = val; // assign array index value
}
}
void print(string strArr[], int s) //defining print method
{
for (int i=0;i<s;i++) //using loop to print array values
{
cout << strArr[i] << endl; //print values
}
cout << endl;
}
Explanation:
In the above-given code, two methods "selectionsort and print" is declared, in which, both method stores two variable in its parameter, which can be described as follows:
- Insides the selectionSort method, two integer variable "i and ind" and a string variable "val" is defined, inside the method a loop is declared, that uses the if block condition to sort the array.
- In the next line, another method print is declared that declared the loop to prints its value.
- Please find the attachment for full code.