Skip to content
Snippets Groups Projects
Commit 46eb7e04 authored by RADELLAH Badr's avatar RADELLAH Badr
Browse files

Ex2 tp1

parent 2fa4b22b
No related branches found
No related tags found
No related merge requests found
Pipeline #31110 passed
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();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment