Online C++ Compiler

#include <bits/stdc++.h> using namespace std; int main() { //create a stack container stack <int> newStack; //insert elements to a stack newStack.push(10); newStack.push(20); newStack.push(30); newStack.push(40); //check whether the values are pushed in stack or not //using empty() if(!newStack.empty()) { //calculate size of a stack cout<<"Stack size is: "<< newStack.size(); } else { cout<<"Stack is empty"; } cout<<"\nElements in the stack are:"; while(!newStack.empty()) { cout<<" "<< newStack.top(); newStack.pop(); } return 0; }