Advertisement
MOISES_QUISPE_ROJAS

Estructura Datos 2021 - TP04 P02

Oct 27th, 2021
1,206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.50 KB | None | 0 0
  1. /* Estructura de Datos - Facultad de Ingenieria - Universidad Nacional de Jujuy
  2.  *
  3.  * @Autor: Equipo 4.1
  4.  */
  5.  /*      @integrantes:                  |    @Carrera:             |   @LU:
  6.                                         |                          |
  7.    Flores ,Cesar Ismael                 | Lic. en Sistemas         | 1782
  8.    Llampa, Ariel Angel Gabriel          | Ing. Informatica         | 8445
  9.    Machaca, Rodrigo Agustin             | Ing. Informatica         | 8512
  10.    Perez, Emanuel Ismael                | Ing. Informatica         | 8393
  11.    Quispe Rojas, Moises Esteban Nicolas | Ing. Informatica         | 7286
  12.  
  13.     Codifique una implementación de la clase Stack<T> (Pila genérica) utilizando en la estructura interna una
  14.     lista genérica.
  15.     Indicaciones:
  16.     Se espera una correcta modularización entre el código que realiza la prueba y validación de la
  17.     implementación respecto del código que hace lo que se solicita en el ejercicio.
  18.  */
  19.  
  20. package List;
  21.  
  22. public class Stack<ELEMENT> {
  23.  
  24.     private ILinkedList data;
  25.     private Integer count;
  26.  
  27.     public Stack(){
  28.         this.data = new SimpleLinkedList<ELEMENT>();
  29.         this.count=0;
  30.     }
  31.     public boolean empty(){
  32.         return this.count <= 0;
  33.     }
  34.    
  35.     public void push(ELEMENT element){
  36.         this.data.addFirst(element);
  37.         ++this.count;
  38.     }
  39.    
  40.     public ELEMENT peek(){
  41.         if(this.empty()){
  42.             throw new RuntimeException("La pila está vacía...");
  43.         }
  44.         return (ELEMENT) this.data.peekFirst();
  45.     }
  46.    
  47.     public ELEMENT pop(){
  48.         if(this.empty()){
  49.             throw new RuntimeException("La pila esta vacia");
  50.         }
  51.         --this.count;
  52.         return (ELEMENT) this.data.removeFirst();      
  53.     }
  54.    
  55.     public int size(){
  56.         return this.count;
  57.     }
  58.    
  59.     @Override
  60.     public String toString(){
  61.         if(this.size()<=0){
  62.             return "";
  63.         }
  64.         return this.data.toString();
  65.     }
  66. //    Demo probar codigo:
  67. //    public static void main(String[] args) {
  68. //        Stack<String> s= new Stack<>();
  69. //        System.out.println("Esta vacio: "+s.empty());
  70. //        s.push("1");
  71. //        s.push("3");
  72. //        s.push("6");
  73. //        System.out.println("Stack: "+s);
  74. //        System.out.println("El que esta en la sima es: "+s.peek());
  75. //        s.pop();
  76. //        System.out.println("Stack nuevo: "+s);
  77. //                
  78. //        System.out.println("El que esta en la sima es: "+s.peek());
  79. //    }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement