Q:编写程序,使用stable_sort和isshorter将传递给你的elimdups版本的vector排序。打印vector的内容,验证你的程序的正确性。
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<iterator>
using namespace std;
void elimdups(vector<string> &s);
bool isshorter(const string &s1,const string &s2);
int main(void){
char *p[]={"indicate","apple","red","ramos","apple","rockets","red","world","end","blue","white","wx","misaya","end"};
vector<string> strs(begin(p),end(p));
elimdups(strs);
stable_sort(strs.begin(),strs.end(),isshorter);
for(auto i:strs)
cout<<i<<' ';
cout<<endl;
return 0;
}
void elimdups(vector<string> &s){
sort(s.begin(),s.end());
auto end_unique=unique(s.begin(),s.end());
s.erase(end_unique,s.end());
}
bool isshorter(const string &s1,const string &s2){
return s1.size()<s2.size();
}