From 20cd57cf81239a3e8067610b4365a692ca5009c9 Mon Sep 17 00:00:00 2001 From: shellhub Date: Sat, 28 Sep 2019 22:29:47 +0800 Subject: [PATCH] init with DEFAULT_CAPACITY --- DataStructures/Queues/Queues.java | 12 ++++++++++++ DataStructures/Stacks/StackArray.java | 12 ++++++++++++ 2 files changed, 24 insertions(+) diff --git a/DataStructures/Queues/Queues.java b/DataStructures/Queues/Queues.java index f9bb42e4a..d5b9a8e5c 100644 --- a/DataStructures/Queues/Queues.java +++ b/DataStructures/Queues/Queues.java @@ -9,6 +9,11 @@ package DataStructures.Queues; * */ class Queue { + /** + * Default initial capacity. + */ + private static final int DEFAULT_CAPACITY = 10; + /** * Max size of the queue */ @@ -30,6 +35,13 @@ class Queue { */ private int nItems; + /** + * init with DEFAULT_CAPACITY + */ + public Queue() { + this(DEFAULT_CAPACITY); + } + /** * Constructor * diff --git a/DataStructures/Stacks/StackArray.java b/DataStructures/Stacks/StackArray.java index cc8596293..88da42cd3 100644 --- a/DataStructures/Stacks/StackArray.java +++ b/DataStructures/Stacks/StackArray.java @@ -34,6 +34,11 @@ public class StackArray { System.out.println(myStackArray.peek()); // will print 2 } + /** + * Default initial capacity. + */ + private static final int DEFAULT_CAPACITY = 10; + /** * The max size of the Stack */ @@ -49,6 +54,13 @@ public class StackArray { */ private int top; + /** + * init Stack with DEFAULT_CAPACITY + */ + public StackArray() { + this(DEFAULT_CAPACITY); + } + /** * Constructor *