Why such strange behaviour of priority queue size() function.

Правка en7, от vintage_Petr_Mitrichev, 2019-06-13 00:34:52

Why such strange behaviour while outputting the difference in sizes of two queues. When i am storing them in a diff variable its showing right answer, while just outputting the difference gives wrong answer.

code

#include<bits/stdc++.h>
using namespace std;
int main()
{
    priority_queue<int , vector<int> , greater<int> > pmin;
    priority_queue<int , vector<int> >pmax;
    pmin.push(5);
    pmin.push(9);
    pmin.push(10);
    pmax.push(1);
    cout << pmax.size() - pmin.size() << endl;
    int diff = pmax.size() - pmin.size();
    cout << diff <<endl;
    return 0 ;
}

**** TO DV : Since downvotes doesn't affects me, but I think this is a very good question whom most of have no idea about the flaw in this. So it would be good if some good answers known to other people.

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en7 Английский vintage_Petr_Mitrichev 2019-06-13 00:34:52 8 Tiny change: '\n****\n**Since down' -> '\n****\n**TO DV : Since down'
en6 Английский vintage_Petr_Mitrichev 2019-06-13 00:34:11 25 Tiny change: 'affects me as most of them know why, but I th' -> 'affects me, but I th'
en5 Английский vintage_Petr_Mitrichev 2019-06-13 00:31:45 20 Tiny change: 'd answers would be here.**' -> 'd answers known to other people.**'
en4 Английский vintage_Petr_Mitrichev 2019-06-13 00:30:54 7 Tiny change: ' if some great answers w' -> ' if some good answers w'
en3 Английский vintage_Petr_Mitrichev 2019-06-13 00:28:21 216
en2 Английский vintage_Petr_Mitrichev 2019-06-12 23:32:49 71
en1 Английский vintage_Petr_Mitrichev 2019-06-12 23:32:15 640 Initial revision (published)