Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 按字母顺序逐段排序数组_C++_Sorting_Character Arrays - Fatal编程技术网

C++ 按字母顺序逐段排序数组

C++ 按字母顺序逐段排序数组,c++,sorting,character-arrays,C++,Sorting,Character Arrays,我试图按字母顺序对输入文件中频率相同的字符串数组进行排序。我首先循环遍历整个数组,并在这组单词具有相同频率的点设置索引。然后我在给定的索引之间插入排序。下面是函数: //Insertion sort up the array, checking for same frequencies and moving words alphabetically downwards int startIdx = 0; int endIdx = 0; for(int k = 0; k < freq.len

我试图按字母顺序对输入文件中频率相同的字符串数组进行排序。我首先循环遍历整个数组,并在这组单词具有相同频率的点设置索引。然后我在给定的索引之间插入排序。下面是函数:

//Insertion sort up the array, checking for same frequencies and moving words alphabetically downwards
int startIdx = 0;
int endIdx = 0;
for(int k = 0; k < freq.length(); k++) {
    if(freq.at(startIdx) == freq.at(k)) {
        endIdx++;
    }
    else { 
        insertionSort(startIdx, endIdx); //Sort the string array at the given indices
        startIdx = endIdx = k;
    }
}
//插入对数组进行排序,检查相同的频率并按字母顺序向下移动单词
int startIdx=0;
int-endIdx=0;
对于(int k=0;k

该函数没有对数组进行排序…当索引设置为0 to length()或其他任意设置的值时,该函数会起作用,但在其他情况下,该函数不起作用。

是否尝试按字母顺序对整数数组进行排序?你能试着重新措辞你的问题吗?目前还不是很清楚。听起来你是在复印件上排序,而不是在原件上排序。调试器显示了什么?@juanchopanza对不起,我是说字符串。整数数组与cstring数组并排。为清晰起见进行了编辑。我正在按原样编辑原始数组。调试器向我显示排序从组中的索引开始的位置,并提供指针的地址。words.setAt()用于交换字符串数组中的元素。@taylorbish实现排序算法是您的家庭作业,还是您可以使用
std::sort
?因此,调试器会在
words.setAt()
序列之后显示交换的值?如果是,则显示的阵列与正在交换的阵列不同。确保正在进行排序的数组以及在所有这些工作之后显示为最终结果的数组实际上是相同的数组。原因是,如果值按照调试器所示进行交换,那么它们将在该函数之外进行交换——如果它们是相同的数组。否则:它是一个副本。