diff --git a/src/main/java/stack.java b/src/main/java/stack.java new file mode 100644 index 0000000000000000000000000000000000000000..3eed5c287d4478808c038e01644b7e3af3b3e33d --- /dev/null +++ b/src/main/java/stack.java @@ -0,0 +1,36 @@ +public class stack { + + private Vector vector; + + public stack() { + vector = new Vector(); + } + + public void push(int value) { + vector.add(value); + } + + public int peek() { + if (vector.isEmpty()) { + throw new IllegalStateException("La pile est vide"); + } + return vector.get(vector.size() - 1); + } + + public int pop() { + if (vector.isEmpty()) { + throw new IllegalStateException("La pile est vide"); + } + int topElement = vector.get(vector.size() - 1); + vector.resize(vector.size() - 1); + return topElement; + } + + public int size() { + return vector.size(); + } + + public boolean isEmpty() { + return vector.isEmpty(); + } +}