Pila en javascript

  //creando la clase pila
      var Stack = function(size){
          this.Size=size;
          this.Stacker = new Array(size);
          this.pointer=0;
 
          //funciones
 
          //inserta a la pila
          this.Push = function(cadena){
              if(this.IsFull()==false){
                  this.Stacker[this.pointer]=cadena;
                  this.pointer++;
                  return true;
              }
              else{
                  return false;
              }
          }
 
 
          //saca de la pila
          this.Pop = function(){
              if(this.IsEmpty!=true){
                  this.pointer--;
                  return this.Stacker[this.pointer];
              }
              else{
                  return false;
              }
          }
 
          //esta vacia?
          this.IsEmpty = function(){
              if(this.pointer==0) return true;
              else return false;
          }
 
          //esta llena?
          this.IsFull = function(){
              if(this.pointer==this.Size) return true;
              else return false;
          }
      }

3 Comments

  1. Posted March 18, 2008 at 11:19 pm | Permalink

    Gracias, pero, pues, si el Array ya contiene un push y actúa como pila, entonces, ahorraríamos mas código. Esta era solo una manera de explicar los multi-usus que tiene javascript.

  2. Posted March 18, 2008 at 11:25 pm | Permalink

    muy bien pero seria mejor usar prototype para reducir codigo

  3. BIANCA
    Posted May 28, 2010 at 6:55 pm | Permalink

    es muy bueno que por medio del esta pagina nos ayuden sobre este tema pero mejor si nos dan mas ejemplos
    bye se cuidan

Post a Comment

Your email is never shared. Required fields are marked *

*
*