C ++选择字符串对象的数组排序 [英] C++ Selection Sort of an Array of String Objects
本文介绍了C ++选择字符串对象的数组排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想为用户输入的字符串对象数组实现一个选择排序函数。我是在正确的道路上远至参数去。感谢
I'm trying to implement a selection sort function for an array of user inputted string objects. Am I on the right path as far as arguments go. Thanks
void selectionSort(char ARRAY[], int size)
{
int startScan, minIndex, minValue;
for (startScan = 0; startScan < (size - 1); startScan++)
{
minIndex = startScan;
minValue = ARRAY[startScan];
for (int index = startScan + 1; index < size; index++)
{
if (ARRAY[index] < minValue)
{
minValue = ARRAY[index];
minIndex = index;
}
}
ARRAY[minIndex] = ARRAY[startScan];
ARRAY[startScan] = minValue;
}
}
推荐答案
可能想使用STL libabry并声明参数为
You probably want to use the STL libabry and declare the argument as
std :: vector< std :: string>
那么排序函数将直接工作,例如
then the sort function will work directly, like this
std::vector< std::string > array;
std::sort (array.begin(), array.end());
这篇关于C ++选择字符串对象的数组排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文