added a Stack class
This commit is contained in:
parent
6f117982d0
commit
e0e75f3b98
1 changed files with 31 additions and 0 deletions
31
Stack.java
Normal file
31
Stack.java
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
// Antoine CRETUAL, Lukian LEIZOUR, 21/02/2024
|
||||||
|
|
||||||
|
import java.util.Vector;
|
||||||
|
|
||||||
|
public class Stack <T> {
|
||||||
|
// Atributes
|
||||||
|
|
||||||
|
private Vector <T> array;
|
||||||
|
|
||||||
|
// Construcors
|
||||||
|
|
||||||
|
public Stack() {
|
||||||
|
array = new Vector<T>();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Methods
|
||||||
|
|
||||||
|
public void push(T x) {
|
||||||
|
this.array.add(this.array.size(), x);
|
||||||
|
}
|
||||||
|
|
||||||
|
public T pop() {
|
||||||
|
T x = this.array.elementAt(this.array.size() - 1);
|
||||||
|
this.array.remove(this.array.size() - 1);
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int size() {
|
||||||
|
return this.array.size();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue