View difference between Paste ID: dXH3S3UC and Tp5hND2Q
SHOW: | | - or go back to the newest paste.
1
public class Stack<T> {
2
	private int tamaño;
3
	private Nodo<T> inicio;
4
	public Stack() {
5
		this.tamaño=0;
6
		this.inicio=null;
7
	}
8
	public int size() {
9
		return this.tamaño;
10
	}
11
	public boolean empty() {
12
		return this.tamaño==0;
13
	}
14
	public void push(T valor) {
15
		Nodo<T>auxiliar=new Nodo<T>(valor);
16
		if(empty()) {
17
			this.inicio=auxiliar;
18
			this.tamaño++;
19
		}else {
20
			auxiliar.setNext(this.inicio);
21
			this.inicio=auxiliar;
22
			this.tamaño++;
23
		}
24
 
25
	}
26
	public T peek() {
27
		return this.inicio.getValor();
28
	}
29
	public void pop() {
30
		if(!empty()) {
31
			this.inicio=this.inicio.getNext();
32
		}
33
	}
34
 
35
}