0
点赞
收藏
分享

微信扫一扫

十个面试排序算法

飞进科技 2023-10-14 阅读 41

stable_sort

假如我们定义一个字符串数组

vector<string> words;
//fox jumps over quick red slow the turtle

这些字符串是按照字典序排列的,我们现在想要words按照单词长度从小到大重排的同时,还希望具有相同长度的元素按照字典序排列:

//比较函数,用来按长度排序单词
bool isShorter(.....)

stable_sort(words.begin(), words.end(), isShorter);
//fox red the over slow jumps quick turtle
举报

相关推荐

0 条评论