0
我正在製作一個撲克評估器,並且我正在使用向量< pair>來存儲數據。現在我被困在排序他們,無論我嘗試我得到編譯器錯誤。排序向量對
任何幫助表示讚賞,謝謝。
class Histogram {
private:
vector< pair<int,int> > _rankHistogram;
vector< pair<int,int> > _suitHistogram;
void add(int rank, int suit) {
for (int i=0; i < _rankHistogram.size(); i++)
if (_rankHistogram[i].first == rank) { _rankHistogram[i].second++; break; }
for (int i=0; i < _suitHistogram.size(); i++)
if (_suitHistogram[i].first == suit) { _suitHistogram[i].second++; break; }
}
bool cmp_big_first (pair<int,int> i, pair<int,int> j) { return i.second < j.second; }
public:
Histogram() {
_rankHistogram.push_back(make_pair(TWO, 0));
_rankHistogram.push_back(make_pair(THREE, 0));
_rankHistogram.push_back(make_pair(FOUR, 0));
_rankHistogram.push_back(make_pair(FIVE, 0));
_rankHistogram.push_back(make_pair(SIX, 0));
_rankHistogram.push_back(make_pair(SEVEN, 0));
_rankHistogram.push_back(make_pair(EIGHT, 0));
_rankHistogram.push_back(make_pair(NINE, 0));
_rankHistogram.push_back(make_pair(TEN, 0));
_rankHistogram.push_back(make_pair(JACK, 0));
_rankHistogram.push_back(make_pair(QUEEN, 0));
_rankHistogram.push_back(make_pair(KING, 0));
_rankHistogram.push_back(make_pair(ACE, 0));
_suitHistogram.push_back(make_pair(SPADES, 0));
_suitHistogram.push_back(make_pair(HEARTS, 0));
_suitHistogram.push_back(make_pair(DIAMONDS, 0));
_suitHistogram.push_back(make_pair(CLUBS, 0));
}
void operator() (Card &c) { add(c.getRank(), c.getSuit()); }
void h_sort() {
sort(_rankHistogram.begin(), _rankHistogram.end(), cmp_big_first);
}
void h_print() {
for (int i=0; i<_rankHistogram.size(); i++) {
cout << Card::rankToString(_rankHistogram[i].first) << "\t\t" << _rankHistogram[i].second << endl;
}
}
而編譯器錯誤是??? – 2012-01-15 20:12:50