Answers for "stack functions c++"

C++
9

stack c++

stack<int> stk;
stk.push(5);
int ans = stk.top(5); // ans =5
stk.pop();//removes 5
Posted by: Guest on April-26-2020
2

cpp stack

// Fast DIY Stack
template<class S, const int N> class Stack {
private:
    S arr[N];
    int top_i;

public:
    Stack() : arr(), top_i(-1) {}
    void push (S n) {
        arr[++top_i] = n;
    }
    void pop() {
        top_i--;
    }
    S top() {
        return arr[top_i];
    }
    S bottom() {
        return arr[0];
    }
    int size() {
        return top_i+1;
    }
};
Posted by: Guest on February-02-2021
1

stack c++

#include <bits/stdc++.h> 

stack<int> stk;
stk.push(5);
int ans = stk.top(5); // ans =5
stk.pop();//removes 5
Posted by: Guest on November-02-2020
0

how to implement stack c++

// CPP program to illustrate 
// Implementation of push() function 
#include <iostream> 
#include <stack> 
using namespace std; 
  
int main() 
{ 
    // Empty stack 
    stack<int> mystack; 
    mystack.push(0); 
    mystack.push(1); 
    mystack.push(2); 
  
    // Printing content of stack 
    while (!mystack.empty()) { 
        cout << ' ' << mystack.top(); 
        mystack.pop(); 
    } 
}
Posted by: Guest on June-26-2021
0

stack in c++

#take input 2D vector

vector<vector<int> > v;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
v[i].push_back(data);
}}
Posted by: Guest on July-09-2021

Browse Popular Code Answers by Language