Update Stack Using Array.cpp

dynamically allocating memory to `stack` according to size given by user as input
This commit is contained in:
Ashwek Swamy
2018-10-27 21:18:51 +05:30
committed by GitHub
parent 14fd8c7821
commit 62c1c5e956

View File

@@ -1,12 +1,12 @@
#include<iostream>
using namespace std;
int stack[10];
int top=0;
int *stack;
int top=0, size;
void push(int x)
{
if(top==10)
if(top==size)
{
cout<<"\nOverflow";
}
@@ -42,6 +42,9 @@ void topmost()
}
int main()
{
cout<<"\nEnter Size of stack : ";
cin>>size;
stack = new int[size];
int ch, x;
do
{