1stack<int> stk;
2stk.push(5);
3int ans = stk.top(5); // ans =5
4stk.pop();//removes 5
1/* Stack is a data structure that provides two O(1) time operations:
2adding an element to the top and removing an element from the top.
3It is only possible to access the top element of a stack. */
4stack<int> s;
5s.push(3);
6s.push(2);
7s.push(5);
8cout << s.top(); // 5
9s.pop();
10cout << s.top(); // 2
1// Fast DIY Stack
2template<class S, const int N> class Stack {
3private:
4 S arr[N];
5 int top_i;
6
7public:
8 Stack() : arr(), top_i(-1) {}
9 void push (S n) {
10 arr[++top_i] = n;
11 }
12 void pop() {
13 top_i--;
14 }
15 S top() {
16 return arr[top_i];
17 }
18 S bottom() {
19 return arr[0];
20 }
21 int size() {
22 return top_i+1;
23 }
24};
1#include <bits/stdc++.h>
2
3stack<int> stk;
4stk.push(5);
5int ans = stk.top(5); // ans =5
6stk.pop();//removes 5
1#take input 2D vector
2
3vector<vector<int> > v;
4for(int i=0;i<n;i++){
5for(int j=0;j<m;j++){
6v[i].push_back(data);
7}}