mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-09 03:59:38 +08:00
Merge pull request #924 from shellhub/master
init with DEFAULT_CAPACITY
This commit is contained in:
@ -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
|
||||||
*
|
*
|
||||||
|
@ -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
|
||||||
*
|
*
|
||||||
|
Reference in New Issue
Block a user