cpp stack

#include <iostream>
using namespace std;
int stack[100], n=100, top=-1;
void push(int val) {
   if(top>=n-1)
   cout<<"Stack Overflow"<<endl;
   else {
      top++;
      stack[top]=val;
   }
}
void pop() {
   if(top<=-1)
   cout<<"Stack Underflow"<<endl;
   else {
      cout<<"The popped element is "<< stack[top] <<endl;
      top--;
   }
}
void display() {
   if(top>=0) {
      cout<<"Stack elements are:";
      for(int i=top; i>=0; i--)
      cout<<stack[i]<<" ";
      cout<<endl;
   } else
   cout<<"Stack is empty";
}
int main() {
   int ch, val;
   cout<<"1) Push in stack"<<endl;
   cout<<"2) Pop from stack"<<endl;
   cout<<"3) Display stack"<<endl;
   cout<<"4) Exit"<<endl;
   do {
      cout<<"Enter choice: "<<endl;
      cin>>ch;
      switch(ch) {
         case 1: {
            cout<<"Enter value to be pushed:"<<endl;
            cin>>val;
            push(val);
            break;
         }
         case 2: {
            pop();
            break;
         }
         case 3: {
            display();
            break;
         }
         case 4: {
            cout<<"Exit"<<endl;
            break;
         }
         default: {
            cout<<"Invalid Choice"<<endl;
         }
      }
   }while(ch!=4);
   return 0;
}

4.33
6
Rob Johansen 105 points

                                    /* Stack is a data structure that provides two O(1) time operations:
adding an element to the top and removing an element from the top.
It is only possible to access the top element of a stack. */
stack&lt;int&gt; s;
s.push(3);
s.push(2);
s.push(5);
cout &lt;&lt; s.top(); // 5
s.pop();
cout &lt;&lt; s.top(); // 2

4.33 (6 Votes)
0
0
0
Zene 95 points

                                    #take input 2D vector

vector&lt;vector&lt;int&gt; &gt; v;
for(int i=0;i&lt;n;i++){
for(int j=0;j&lt;m;j++){
v[i].push_back(data);
}}

0
0
5
1
Mckeed 100 points

                                    #include &lt;bits/stdc++.h&gt; 

stack&lt;int&gt; stk;
stk.push(5);
int ans = stk.top(5); // ans =5
stk.pop();//removes 5

5 (1 Votes)
0
4.3
9
Steveh 110 points

                                    stack&lt;int&gt; stk;
stk.push(5);
int ans = stk.top(5); // ans =5
stk.pop();//removes 5

4.3 (10 Votes)
0
4
4
Cliff Hall 95 points

                                    // Fast DIY Stack
template&lt;class S, const int N&gt; 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;
    }
};

4 (4 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
stack using array c++ how to make the stack in cpp how to define stack in c++ take stack in c++ call stack implementation in c++ implement stack in cpp all the functions in stack in c++ stack in c++ code implement stack from scratch in c++ stack basic operations c++ use stack in c++ c++ stack operations stack implementation using class in c++ code stack in c++ build stack in c++ creating a stack in c++ stack implemention in c++ how to implement a stack in c++ c++ stack data structure implement stack in c++ C++ create stack using stack c++ implementing stack using c++ c++ std stack example c++ stack methods implementation of stack c++ stack data structure in c++ example of stack stl c++ how is a stack implemented in c++ stack in c++ cplusplus stack using array in c ++ example stack using array in c ++ stl stack in cpp what's stack in c++ whats stack in c++ stack adt in c++ stack in cpp using array stack cpp program stack c++ ckear how stack in made in c++ operations on stack c++ use a stack in c++ stack using c++ stack stl cpp stack algorithm c++ Stack implementation using array in C++ function call stack in c++ call stack in c++ stack in data structure c++ std::stack cpp stack simple example in c++ stack in cpp stl how to implement stack c++ stack implementation in c++ what is call stack in c++ Stack ds in c++ stack c+= functions stc++ stack stack c++ for cp stack basics in cpp does c++ have in built stack stack syntax in cpp the stack cpp C++ stack structure stack properties c++ stack code in cpp Stack (C++) c++ stack algorithm functions of stack in cpp stack operations stl c++ how to implement stack in c++ class stack c++ example stack c++ implementation stack documentation c++ c++ stack container stack dsa c++ stack implementation with c++ algorithm stack implementation with c++ hwo to implement stack in c++ stack code c++ functions in stack stl c++ stack operation c++ code stack in cpp? what is stack in c++ stack c++ builtin c++ stack functions stack int c++ stack in c++ data structure stack oin cpp stack in stl cc++ stack implementation C++ create stack class c++ how to include stack in cpp stack stl c++ functions how do we use stack in c++ stack defined in c++ making a stack in c++ stack representation in c++ stl stack in c++ example stack using class in cpp cpp stack stl in c stack definition in c++ stack contains c++ c++ creating a stack c++ stl library stack stack in c++ stl methods define stack in c++ c++ stack.h stack keyword in c++ stack implementation using cpp stack stl c++ cp algorithms functions in c++ stack stl basic stack in c++ c++ stack oop implement in stack in c++ c++ stack in class stack in class c++ stack class in c++ code stack c++ class c++ programs on stack stack class cpp how to create a stack class in c++ how to implement a stack c++ stack c++ geek writing a stack in c++ c++ called stack c++ stack code class stack C++ stack operation c++ stack declaration cpp stack operations in cppp stack operation in cpp stack algorithm in c++ stack in c++ cppreference c++ stack include define a stack class in c++ define a stack in c++ how to create stack in c++ stack standard library c++ c++ call stack c+++ stack clea library of stack in c++ Writing a stack class in c+ creating a stack class in c++ stack c++ c++ stack documentation creating a stack c++ stack c++ reference what is a stack in c++ what is an stack in c++ hpw to define a stack c++ include stack c++ stack class implementation c++ stack in c++ stl; c++ stack implementation stack inb c++ stack implementation cpp how to declare a stack in c++ stack c++ example implement stack c++ stack using class in c++ program using stack in C++ stack method in c++ call stack c++ functions for stack in c++ stack in c++; stack stl functions cp.stack.com cpp reference stack Cpp stl stack c++ stack \ inbuilt stack and queue in c++ stack stl in cpp stack ++ full stack c++ stack implementation in cpp display all the element of the stack using stl c++ include stacks stack operations in stl c++ sstack.cpp std::stack.back stack &lt;int*&gt; meaning stacks C++ gee how to declare stack in c++ stack in c++ gfg push and pop operation in stack using c++ how to make a stack in c++ c++ stl stack find stack functions in stl stac in cpp stack fuctions stl &quot;used as an underlying container for the stack&quot; library function in stl to display stack in c++ stack insert how to search in stack and set in c++ how to stack c++ c++ stl in c++ for stack stack in stl in c++ stack using cpp operations used in stack data structure stl STL FILO container how to initialize a stack in c++ stack in c++ funcitons stack.peek c++ push and pop in cpp stack template c++14 is empty function get data in stack c++ how to access stack elements in c++ stacks cpp pop in stack c++ stl stack std is stl stack a vector how to push onto the stack in c++ cpp stack example stack stl functions c++ stack order c++ stack library c++ c++ stack contain c++ stack (.pop) stack char c++ stack i c++ does c++ have a stack type stack in c+= stack data structure using stl std stack c++ create stack c++ stack c_++ c++ stack container variable how to return a stack in c++ how to pop up value in stack c++ data structure stack &lt;&gt; cpp c++ stack.end stack class functions c++ does c++ have a stack stack program in c++ stack complexity c++ the stack c++ inbuilt stack in cpp char stack push display in c++ Implementation of Stack with STL.Basic satck stl declare stack in c++ stl in c for stack stack stl c how to get to any position in the stack in c++ class functions c++ stack stack.begin() stl stack underlying data structure show stack function in c++ include stack in c++ c++ what to use a stack on pushcharacter stack C++ full in stack stl reference stack c++ display stl stack element include stack define stacks in cpp stack C++ key complexity of c++ stack stack.back() stack in c++ st; stack in std c++ geeksforgeeks stack c++ stack use in cpp stack c+ stack operations in cpp stack inc++ declare a stack in c++ a stack class has member functions for what c++ stl stack methods stack&lt;char, list&lt;char&gt;&gt; containers c++ stl stack\ c++ stack peek stack in stkl stack stl funtions stack program using STl what is the fron tof a stack c++ c++ stack insert std stack c++ define stack c++ stack std stacks display a stack c++ how do you use a stack library in c++ how do you use a stack library c++ stack useful built in stack c++ how many elements stack can add in cpp declare a stack c++ stack of nod* type in c++ stack using stl function(stack&lt;int&gt; ) how to write c++ stack code of push and pop function in c++ stack in stl functions vector stack c++ create stack in c++ push and pop function in stack in c++ stack std c++ library stack functions c++ c++ stack class how to print a stack stl in c++ stack cod ein c++ how to create aray of stacks stl how to create 10 stacks stl hw to use the stack in c++ using stack in c++ stack cpp c c++ stl stack traversal c++ stack traverse defining stack in c++ stack and queue stl stack library define stack c++ stl stack c++ functions stack of class c++ stack library in cpp stack stl operations stack with stl stack class c++ file stack class c++ make stack c++ does array of the stacks exist in c++ stack in stl stack cplusplus intializing stack in C++ cplusplus stack stl stack new stack in c++ stack commands c++ how to use stacks c++ how to use a stack c++ stl for stack in c++ which are different member functions of stack container? cpp code for stack for any data type What are the time complexity of stack::top() and stack::push() in C++ STL? initializing stack in c++ stack program using stl c++ intialise stack in cpp show stack c++ develop an application cpp stack storing packets produced factor hippo or pippo in stack c++ how to create a stack in c++ stack n c++ stcks C++ inbuilt stack in c++ c++ stl stack stack operations in c++ how to use a stack in c++ how to add numbers already inside stack in c++ stack cpp stl Add elements to a stack c++ using a vector Add elements to a stack c++ how to make stack in c++ stack header file i n c++ stack.back() in C++ stack and queue in c++ stl how to make a stack of strings in c++ initialize stack in c++ haow to traverse and push the data at the same time in C++ how to iterate stack in c++ stl how to print stack in c++ how to include stack in c++ how to use stl stack in c++ stack implementation in c++ stl how to apply a stack in c++ stakc c++ stl how to use stack in c++ implement stack inc functions cpp stack methods in c++ declaration of stack in c++ #include stack in c++ stack&lt;Node*&gt; stk1; in c++ cpp stak initalise a stack in c++ stack find functionc++ stacks w3resourses cpp simple stack question cpp stack vector definition c++ print elements of stack in c++ stack stl c++ find cpp user in stack c++ stachs stl how to reserve the stack in c++ declaring a stack in c++ c++ stack library stack function in c++ stack full function in c++ stl stack declaration in c++ stack class in c++ initialize stack c++ c++ stack stl library stl stack in c++ stl stack c++ stack in c++ geeksforgeeks stack operations c++ printing a stack in c++ stack in c++stl pop stack c++ stack for strings c++ c++ stack stl stack pop c++ stack front c++ c++ stack pop use stack in cpp stack c++ STACK IN C++\ stack in cpp #stack c++ stack begin c++ how to use stack in cp stack erase c++ stack list c++ stack type how to initialize stack in cpp stacks stl stack in c++ stl c++ stacks cpp how to use stack stack std c++ stacks in c++ stl statck c++ stack c++.com stack functions in c++ how to find function in stack stack c++ stl stack stl stacks c++ stl c++stack stackin cpp stl python stack stack c++ functions stack cpp how to use stack in cpp cpp stack stl stack library in c++ stack stl in c++ stack function in cpp stack methods c++ stacks in cpp stack built in functions in c++ stacks in c++ stack library for c++ stack functions in cpp making a stack of list c++ header file for stack in c++ stack header file in c++ stacks c++ stack stl c++ c++ stack exmaple stack in stl c++ c++ what are stacks stack[i] c++ add all elements of stack c++ c++ stack example stack in c++ stack stl c++ cpp stack c++ stack stack c++
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source