Answers for "stack implementation in c++ using array"

C++
1

push pop code in c++

#include<iostream>
using namespace std;
#define Max 100
class stack{
	public:
		int top;
		int size;
		int *s;
		int stack[Max];
		
		void push()
		{
			int value;
			if(top==size-1)
			{
				cout<<"overflow";
			}
			else
			{
				cout<<"Enter value to push n";
				cin>>value;
				top++;
				stack[top]=value;
			}
		}
		int pop()
		{
			if(top==-1)
			{
				cout<<"Underflow";
			}
			else
			{
				cout<<"Deleted value is n"<<stack[top];
				top--;
			}
		}
		void display()
		{
			int i;
			for(i=top;i>=0;i--)
			{
				cout<<stack[i]<<endl;
			}
		}
};
int main()
{
	stack st;
	cout<<"Enter the size of the stack";
	cin>>st.size;
	st.s=new int[st.size];
	st.top=-1;
	int ch;
	while(st.size!=0)
	{	
	cout<<endl<<"    #####       STACK MENU     #####     "<<endl;
	cout<<"1. PUSH OPERATION n2. POP OPERATION n3. DISPLAY n4.Exit n";
	cin>>ch;
	switch(ch)
	{
		case 1: 
		    st.push();
		    break;
		case 2:
			st.pop();
			break;
		case 3:
			st.display();
			break;
		case 4:
			exit(0);
			
		default:cout<<"n Choose correct option";
	}
}
return 0;
}
Posted by: Guest on September-26-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

Code answers related to "stack implementation in c++ using array"

Browse Popular Code Answers by Language