首页 > 代码库 > 链表的特有算法操作

链表的特有算法操作

10.42 使用list的算法实现排序和删除重复元素。

#include<algorithm>#include<list>#include<iostream>#include<string>using namespace std;void elimDup(list<string> &words){    words.sort();    words.unique();}bool isShorter(const string &s1,const string &s2){    return s1.size()<s2.size();}int main(){    list<string> v2={"aaa","aaaaa","dfdaaaa","fdaa","aaa","dfaaaaa","aaaaa"};    elimDup(v2);    for(auto vv:v2)        cout<<vv<<" ";    cout<<endl;    return 0;}