Stack

#include<iostream>
#include<stack>
using namespace std;

int main() {

	/* Create a stack */
	stack<int> data;

	/* Push data into the stack */
	data.push(10);
	data.push(20);
	data.push(30);
	data.push(40);
	
	cout << "Stack size: " << data.size() << endl;
	cout << "Data on top of the stack: " << data.top() << endl;

	/* Pop data from the stack */
	data.pop();

	cout << "Stack size after pop: " << data.size() << endl;
	cout << "Now top data on stack: " << data.top() << endl;
	
	return 0;
}


/* Output */
Stack size: 4
Data on top of the stack: 40
Stack size after pop: 3
Now top data on stack: 30

Comments (0)

  • To add your comment please or

We use cookies to improve your experience on our site and to show you personalised advertising. Please read our cookie policy and privacy policy.

Got It!