2个回答
展开全部
重载operator<,只需要<,不需要>
没重载啊⋯⋯没重载根本不让你用
没重载啊⋯⋯没重载根本不让你用
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include <iostream>
#include <set>
#include <string>
using namespace std;
struct Word
{
string str;
int prob;
Word( string s, int i):str(s),prob(i){};
Word(){};
};
struct MapCmp
{
bool operator()(const Word s1, const Word s2) const
{
if( s1.prob != s2.prob )
return s1.prob > s2.prob;
return s1.str.compare(s2.str) > 0;
}
};
typedef multiset<Word, MapCmp> Mapwords;
Mapwords words;
int main()
{
words.insert(Word("hello",1));
words.insert(Word("hell",1));
words.insert(Word("hell",2));
words.insert(Word("third",3));
words.insert(Word("ok",3));
words.insert(Word("jjjj",-2));
Mapwords::iterator mbegin;
Mapwords::iterator mend = words.end();
for( mbegin = words.begin(); mbegin != mend; ++mbegin)
cout<<mbegin->str<<'\t'<<mbegin->prob<<endl;
getchar();
return 0;
}
#include <set>
#include <string>
using namespace std;
struct Word
{
string str;
int prob;
Word( string s, int i):str(s),prob(i){};
Word(){};
};
struct MapCmp
{
bool operator()(const Word s1, const Word s2) const
{
if( s1.prob != s2.prob )
return s1.prob > s2.prob;
return s1.str.compare(s2.str) > 0;
}
};
typedef multiset<Word, MapCmp> Mapwords;
Mapwords words;
int main()
{
words.insert(Word("hello",1));
words.insert(Word("hell",1));
words.insert(Word("hell",2));
words.insert(Word("third",3));
words.insert(Word("ok",3));
words.insert(Word("jjjj",-2));
Mapwords::iterator mbegin;
Mapwords::iterator mend = words.end();
for( mbegin = words.begin(); mbegin != mend; ++mbegin)
cout<<mbegin->str<<'\t'<<mbegin->prob<<endl;
getchar();
return 0;
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询