From 9ac82a1a2662f14e94ffd9771f4e0d1c15314adf Mon Sep 17 00:00:00 2001 From: Mahmoud khalil Date: Sun, 1 Apr 2018 20:50:41 +0300 Subject: [PATCH] Update Stacks.java --- Data Structures/Stacks/Stacks.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Data Structures/Stacks/Stacks.java b/Data Structures/Stacks/Stacks.java index 95469b91..2861ef5c 100644 --- a/Data Structures/Stacks/Stacks.java +++ b/Data Structures/Stacks/Stacks.java @@ -43,6 +43,7 @@ class Stack{ stackArray[top] = value; }else{ resize(maxSize*2); + push(value);// don't forget push after resizing } } @@ -58,6 +59,7 @@ class Stack{ if(top < maxSize/4){ resize(maxSize/2); + return pop();// don't forget pop after resizing } else{ System.out.println("The stack is already empty"); @@ -80,9 +82,11 @@ class Stack{ } private void resize(int newSize){ - private int[] transferArray = new int[newSize]; + //private int[] transferArray = new int[newSize]; we can't put modifires here ! + int[] transferArray = new int[newSize]; - for(int i = 0; i < stackArray.length(); i++){ + //for(int i = 0; i < stackArray.length(); i++){ the length isn't a method . + for(int i = 0; i < stackArray.length; i++){ transferArray[i] = stackArray[i]; stackArray = transferArray; }