What is the correct Compare Statement to find the biggest Value of a Vector full of pairs that are bigger than a specific defined int.
int x = 5;
auto pos = max_element(ownCards.begin(),
ownCards.end(),
[&x](pair<int, int> p1, pair<int, int> p2)
{ return p1.first > x && p1.second > p2.second; });
From the fact that my vector is sorted, I have the upper_bound function still taken to help, this makes the code clearer and faster, still not fast enough unfortunately.
auto start = upper_bound(ownCards.begin(), ownCards.end(), ownCards[j]);
auto pos = max_element(start,
ownCards.end(),
[&x](pair<int, int> p1, pair<int, int> p2) { return p1.second > p2.second; });
Aucun commentaire:
Enregistrer un commentaire