Merge pull request #924 from shellhub/master

init with DEFAULT_CAPACITY
This commit is contained in:
Yang Libin
2019-09-29 09:32:53 +08:00
committed by GitHub
2 changed files with 24 additions and 0 deletions

View File

@ -9,6 +9,11 @@ package DataStructures.Queues;
* *
*/ */
class Queue { class Queue {
/**
* Default initial capacity.
*/
private static final int DEFAULT_CAPACITY = 10;
/** /**
* Max size of the queue * Max size of the queue
*/ */
@ -30,6 +35,13 @@ class Queue {
*/ */
private int nItems; private int nItems;
/**
* init with DEFAULT_CAPACITY
*/
public Queue() {
this(DEFAULT_CAPACITY);
}
/** /**
* Constructor * Constructor
* *

View File

@ -34,6 +34,11 @@ public class StackArray {
System.out.println(myStackArray.peek()); // will print 2 System.out.println(myStackArray.peek()); // will print 2
} }
/**
* Default initial capacity.
*/
private static final int DEFAULT_CAPACITY = 10;
/** /**
* The max size of the Stack * The max size of the Stack
*/ */
@ -49,6 +54,13 @@ public class StackArray {
*/ */
private int top; private int top;
/**
* init Stack with DEFAULT_CAPACITY
*/
public StackArray() {
this(DEFAULT_CAPACITY);
}
/** /**
* Constructor * Constructor
* *