From 0e6b09b01010b47d9d20961854f39c1791c86bf6 Mon Sep 17 00:00:00 2001 From: Shreya Singh Date: Mon, 14 Oct 2024 14:13:50 +0530 Subject: [PATCH] Create ImplementStackUsingArray A program to implement a Stack using Array. The push() method takes one argument, an integer 'x' to be pushed into the stack and pop() which returns an integer present at the top and popped out from the stack. If the stack is empty then return -1 from the pop() method. --- .../stacks/ImplementStackUsingArray | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/main/java/com/thealgorithms/stacks/ImplementStackUsingArray diff --git a/src/main/java/com/thealgorithms/stacks/ImplementStackUsingArray b/src/main/java/com/thealgorithms/stacks/ImplementStackUsingArray new file mode 100644 index 000000000000..ca096330f13f --- /dev/null +++ b/src/main/java/com/thealgorithms/stacks/ImplementStackUsingArray @@ -0,0 +1,32 @@ +class MyStack { + private int[] arr; + private int top; + + public MyStack() { + arr = new int[1000]; + top = -1; + + } + + public void push(int x) { + // Your Code + top++; + if(top