Advertisement
Mercedes

Pila

Mar 29th, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. import prog3.listaenteros.ListaDeEnteros;
  2.  
  3. public class PilaDeEnteros {
  4.  
  5. ListaDeEnteros datos;
  6.  
  7.  
  8. public PilaDeEnteros() {
  9.  
  10. }
  11.  
  12. public void apilar(int elem) {
  13. datos.agregarFinal(elem);
  14. }
  15.  
  16. public int desapilar() {
  17. int elem = datos.elemento(datos.tamanio());
  18. datos.eliminar(datos.tamanio());
  19. return elem;
  20. }
  21.  
  22. public int tope() {
  23. return datos.elemento(datos.tamanio());
  24. }
  25.  
  26. public boolean esVacia() {
  27. if (datos.tamanio()==0)
  28. return true;
  29. else
  30. return false;
  31. }
  32.  
  33. }
  34.  
  35.  
  36.  
  37.  
  38. package prog3.util;
  39.  
  40. public class TestPila {
  41.  
  42.  
  43. public static void main(String[] args) {
  44. PilaDeEnteros p1,p2;
  45. int valor2=0;
  46. p1=new PilaDeEnteros();
  47. p1.apilar(1);
  48. p1.apilar(2);
  49. p2=p1;
  50. valor2 = p2.desapilar();
  51. System.out.println("El valor del tope de la pila p1 es :" + p1.desapilar());
  52.  
  53. }
  54.  
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement