mercredi 15 mars 2023

Stack push pop top function unusual results

I first push into the stack and then pop from it. From the empty stack I cout stack.top() and it prints the element which I have pushed earlier. Why is it so??

        priority_queue<int, vector<int>, greater<int>>minHeap ;

        minHeap.push(1) ;
        minHeap.pop() ;
        cout << minHeap.top() ;

Why the output of this is 1??

Aucun commentaire:

Enregistrer un commentaire