Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Stack<T> {
- private int tamaño;
- private Nodo<T> inicio;
- public Stack() {
- this.tamaño=0;
- this.inicio=null;
- }
- public int size() {
- return this.tamaño;
- }
- public boolean empty() {
- return this.tamaño==0;
- }
- public void push(T valor) {
- Nodo<T>auxiliar=new Nodo<T>(valor);
- if(empty()) {
- this.inicio=auxiliar;
- this.tamaño++;
- }else {
- auxiliar.setNext(this.inicio);
- this.inicio=auxiliar;
- this.tamaño++;
- }
- }
- public T peek() {
- return this.inicio.getValor();
- }
- public void pop() {
- if(!empty()) {
- this.inicio=this.inicio.getNext();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement