Advertisement
LEANDRONIEVA

StackSLL

Oct 25th, 2022
946
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.98 KB | None | 0 0
  1. public class StackSLL <ELEMENT> {
  2.  
  3.     SimpleLinkedList<ELEMENT> lista = new SimpleLinkedList<ELEMENT>();
  4.  
  5.     public StackSLL() {
  6.        
  7.     }
  8.  
  9.     public StackSLL(SimpleLinkedList<ELEMENT> lista) {
  10.         super();
  11.         this.lista = lista;
  12.     }
  13.    
  14.     public boolean empty() {
  15.          return this.lista.size() <= 0;
  16.      }
  17.    
  18.     public ELEMENT peek() {
  19.          if (this.empty()) {
  20.              throw new RuntimeException("La pila está vacía...");
  21.          }
  22.          return this.lista.element();
  23.      }
  24.    
  25.     public ELEMENT pop() {
  26.          if (this.empty()) {
  27.              throw new RuntimeException("La pila está vacía...");
  28.          }
  29.          return this.lista.removeFirst();
  30.      }
  31.    
  32.     public ELEMENT push(ELEMENT element) {
  33.         lista.addFirst(element);
  34.        
  35.         return this.lista.element();
  36.     }
  37.    
  38.     public boolean search(Object object) {
  39.          
  40.          return lista.search(object);
  41.      }
  42.    
  43.     public int size() {
  44.        
  45.          return this.lista.size();
  46.      }
  47.    
  48.     public String toString() {
  49.        
  50.         return this.lista.toString();
  51.     }
  52.    
  53. }
  54.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement