I recently made a data structure, stack implementation in Java and I would like feedback on my code to improve it (other than commenting/documenting my code).
public class Stack {
private int topIndex, maxSize;
private int[] stack;
public Stack(int size) {
maxSize = size;
stack = new int[maxSize];
topIndex = -1;
}
public int maxSize() {
return maxSize;
}
public int size() {
return topIndex + 1;
}
public boolean isEmpty() {
return topIndex == -1;
}
public boolean isFull() {
return (topIndex + 1) == maxSize;
}
public void push(int value) {
if (!isFull()) {
topIndex++;
stack[topIndex] = value;
}
}
public int peek() {
if (!isEmpty()) {
return stack[topIndex];
} else {
return 0;
}
}
public void pop() {
if (!isEmpty()) {
topIndex--;
}
}
public static void main(String[] args) {
}
}