Advertisement
Jurado001

TP3E2 - clases Pila

Sep 13th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.71 KB | None | 0 0
  1. import java.util.ArrayList;
  2.  
  3. public class Pila {
  4.     private int cont=0;
  5.     private ArrayList<Integer>numeros=new ArrayList<Integer>();
  6.    
  7.     //Costructores
  8.     public Pila() {
  9.        
  10.     }
  11.    
  12.     public Pila(Pila copia) {
  13.         for(int i=0;i<copia.cont;i++) {
  14.             numeros.add(copia.numeros.get(i));
  15.             cont++;
  16.         }
  17.     }
  18.    
  19.     //Metodos
  20.     public void Mostrar() {
  21.         if(!EstaVacia()) {
  22.             for (int j=0; j<cont; j++) {
  23.                 System.out.println(numeros.get(j));
  24.             }
  25.         }
  26.         else {
  27.             System.out.println("Está Vacia...");
  28.         }  
  29.     }
  30.    
  31.     public boolean EstaVacia() {
  32.         return cont<=0;
  33.     }
  34.    
  35.     public void Apilar(int aux) {
  36.         numeros.add(aux);
  37.         cont++;
  38.     }
  39.    
  40.     public int Desapilar() {
  41.         cont--;
  42.         return numeros.get(cont);
  43.     }
  44.  
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement