sort函數(shù)我相信大家都不陌生,今天介紹一個新的排序算法stable_sort
stable_sort:穩(wěn)定排序算法,維持相等元素的原有順序。
stable_sort
假如我們定義一個字符串數(shù)組文章來源:http://www.zghlxwxcb.cn/news/detail-725237.html
vector<string> words;
//fox jumps over quick red slow the turtle
這些字符串是按照字典序排列的,我們現(xiàn)在想要words按照單詞長度從小到大重排的同時,還希望具有相同長度的元素按照字典序排列:文章來源地址http://www.zghlxwxcb.cn/news/detail-725237.html
//比較函數(shù),用來按長度排序單詞
bool isShorter(.....)
stable_sort(words.begin(), words.end(), isShorter);
//fox red the over slow jumps quick turtle
到了這里,關(guān)于排序算法(stable_sort(), sort())的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!