0

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

//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;
    }
}

该函数不对数组进行排序......当索引设置为 0 到 length() 或其他一些任意设置的值时它可以工作,否则它不起作用。

4

0 回答 0