From 62c1c5e956c599867903950510de9cf99b77fc2c Mon Sep 17 00:00:00 2001 From: Ashwek Swamy <39827514+ashwek@users.noreply.github.com> Date: Sat, 27 Oct 2018 21:18:51 +0530 Subject: [PATCH] Update Stack Using Array.cpp dynamically allocating memory to `stack` according to size given by user as input --- Datastructures/Stack Using Array.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Datastructures/Stack Using Array.cpp b/Datastructures/Stack Using Array.cpp index 944258ed4..c5ad146cb 100644 --- a/Datastructures/Stack Using Array.cpp +++ b/Datastructures/Stack Using Array.cpp @@ -1,12 +1,12 @@ #include 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 {