Skip to content

Latest commit

 

History

History
27 lines (19 loc) · 626 Bytes

pop.md

File metadata and controls

27 lines (19 loc) · 626 Bytes

pop

Description

pop() function is used to remove an element from the top of the stack(newest element in the stack). The element is removed to the stack container and the size of the stack is decreased by 1.

Example

    #include<stack>
    #include<iostream>

    int main(){
        std::stack<int> mystack;

        mystack.push(0);    //pushing elements using push()
        mystack.push(1);
        mystack.push(2);

        while (!mystack.empty()) {
            std::cout << ' ' << mystack.top();
            mystack.pop();  //deleting elements using pop()
        }

        return 0;
    }