36 lines
662 B
Java
36 lines
662 B
Java
package Week4_Lab;
|
|
|
|
public class StackOfIntegers {
|
|
private int[] elements;
|
|
private int size;
|
|
|
|
public StackOfIntegers(){
|
|
this(16);
|
|
}
|
|
public StackOfIntegers(int capacity){
|
|
this.elements = new int[capacity];
|
|
this.size = -1;
|
|
}
|
|
|
|
public boolean empty(){
|
|
return size == -1;
|
|
}
|
|
public int peek(){
|
|
return elements[size - 1];
|
|
}
|
|
|
|
public void push(int value){
|
|
this.size++;
|
|
this.elements[size] = value;
|
|
}
|
|
public int pop(){
|
|
int value = elements[size];
|
|
this.size--;
|
|
return value;
|
|
}
|
|
public int getSize(){
|
|
return size + 1;
|
|
}
|
|
}
|
|
|