Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Estructura de Datos - Facultad de Ingenieria - Universidad Nacional de Jujuy
- *
- * @Autor: Equipo 4.1
- */
- /* @integrantes: | @Carrera: | @LU:
- | |
- Flores ,Cesar Ismael | Lic. en Sistemas | 1782
- Llampa, Ariel Angel Gabriel | Ing. Informatica | 8445
- Machaca, Rodrigo Agustin | Ing. Informatica | 8512
- Perez, Emanuel Ismael | Ing. Informatica | 8393
- Quispe Rojas, Moises Esteban Nicolas | Ing. Informatica | 7286
- Codifique una implementación de la clase Stack<T> (Pila genérica) utilizando en la estructura interna una
- lista genérica.
- Indicaciones:
- Se espera una correcta modularización entre el código que realiza la prueba y validación de la
- implementación respecto del código que hace lo que se solicita en el ejercicio.
- */
- package List;
- public class Stack<ELEMENT> {
- private ILinkedList data;
- private Integer count;
- public Stack(){
- this.data = new SimpleLinkedList<ELEMENT>();
- this.count=0;
- }
- public boolean empty(){
- return this.count <= 0;
- }
- public void push(ELEMENT element){
- this.data.addFirst(element);
- ++this.count;
- }
- public ELEMENT peek(){
- if(this.empty()){
- throw new RuntimeException("La pila está vacía...");
- }
- return (ELEMENT) this.data.peekFirst();
- }
- public ELEMENT pop(){
- if(this.empty()){
- throw new RuntimeException("La pila esta vacia");
- }
- --this.count;
- return (ELEMENT) this.data.removeFirst();
- }
- public int size(){
- return this.count;
- }
- @Override
- public String toString(){
- if(this.size()<=0){
- return "";
- }
- return this.data.toString();
- }
- // Demo probar codigo:
- // public static void main(String[] args) {
- // Stack<String> s= new Stack<>();
- // System.out.println("Esta vacio: "+s.empty());
- // s.push("1");
- // s.push("3");
- // s.push("6");
- // System.out.println("Stack: "+s);
- // System.out.println("El que esta en la sima es: "+s.peek());
- // s.pop();
- // System.out.println("Stack nuevo: "+s);
- //
- // System.out.println("El que esta en la sima es: "+s.peek());
- // }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement