Skip to content
Snippets Groups Projects
Commit 1c36b05b authored by SAYEH Nahlane ghina's avatar SAYEH Nahlane ghina
Browse files

Création de la classe Vector

Création de la classe Stack
parent 61ac2296
Branches
No related tags found
No related merge requests found
public class Stack {
private Vector vector;
public Stack() {
vector = new Vector(10);
}
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 value = vector.get(vector.size() - 1);
vector.set(vector.size() - 1, 0);
vector.resize(vector.size() - 1);
return value;
}
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