Advertisement
s00rk

[Expresiones Matematica] Pila

Oct 1st, 2011
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.93 KB | None | 0 0
  1. package Tarea;
  2.  
  3. public class Pila
  4. {
  5.     private int Tope = -1;
  6.     private int Max;
  7.     private int Pila[];
  8.     public int DatoPila;
  9.    
  10.     public Pila(int CantMax)
  11.     {
  12.         Pila = new int[CantMax];
  13.         Max = CantMax;
  14.     }
  15.    
  16.     private boolean PilaVacia()
  17.     {
  18.         boolean resp = false;
  19.         if(Tope == -1)
  20.             resp = true;
  21.         return resp;
  22.     }
  23.    
  24.     private boolean PilaLlena()
  25.     {
  26.         boolean resp = false;
  27.         if((Tope-1) == Max)
  28.             resp = true;
  29.         return resp;
  30.     }
  31.    
  32.     public boolean InsertarPila(int Dato)
  33.     {
  34.         boolean resp = false;
  35.         if(!PilaLlena())
  36.         {
  37.             Tope++;
  38.             Pila[Tope] = Dato;
  39.             resp = true;
  40.         }
  41.         return resp;   
  42.     }
  43.    
  44.     public boolean RemoverPila()
  45.     {
  46.         boolean resp = false;
  47.         if(!PilaVacia())
  48.         {
  49.             DatoPila = Pila[Tope];
  50.             Tope--;
  51.             resp = true;
  52.         }
  53.         return resp;
  54.     }
  55.    
  56.     public boolean VerPila()
  57.     {
  58.         boolean resp = false;
  59.         if(!PilaVacia())
  60.         {
  61.             DatoPila = Pila[Tope];
  62.             resp = true;
  63.         }
  64.         return resp;
  65.     }
  66.  
  67. }
  68.  
  69.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement