13th Sep 2007
Pila en javascript
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;
-
}
-
}
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.
muy bien pero seria mejor usar prototype para reducir codigo