Skip to content

Latest commit

 

History

History
26 lines (18 loc) · 535 Bytes

push.md

File metadata and controls

26 lines (18 loc) · 535 Bytes

push

Description

push() function is used to insert an element at the top of the stack. The element is added to the stack container and the size of the stack is increased 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();
        }

        return 0;
    }