作者TonyQ (骨头)
看板Ajax
标题[js]stack
时间Sun Apr 15 18:26:46 2007
板上没啥水...来灌一下...
其实只是个伪 class 真function罢了XD
最近开始想做一些事情
一些必要的结构是需要的...~_~
────────────────────────────────
这边是使用实例
var _mystack=new _stack();
_mystack.push("123");
_mystack.push("23");
_mystack.push("3");
_mystack.push("234");
_mystack.push("34");
for( var i=0;!_mystack.isEmpty();i++){
alert(_mystack.pop());
}
────────────────────────────────
以下是code
function _stack(){
var stack=new Object();
stack.store=new Object();
stack.sindex=-1;
stack.push=function(object){
stack["sindex"]++;
stack["store"][stack["sindex"]]=object;
}
stack.pop=function(){
if(!stack.isEmpty()){
var result= stack["store"][stack["sindex"]];
stack["store"]["s"+stack["sindex"]]=null;
stack["sindex"]--;
return result;
}else{
return null;
}
}
stack.isEmpty=function(){
return stack["sindex"]==-1;
}
stack.peek= function(){
if(!stack["isEmpty"]){
var result= stack["store"][stack["sindex"]];
return result;
}else{
return null;
}
}
stack.size= function(){
return stack["sindex"]+1;
}
return stack;
}
--
String temp="relax"; | Life just like programing
while(buringlife) String.forgot(temp); | to be right or wrong
while(sleeping) brain.setMemoryOut(); | need not to say
stack.push(life.running); | the compiler will
stack.push(scouting.buck()); | answer your life
stack.push(bowling.practice()); | Bone
everything
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 220.134.27.68
※ 编辑: TonyQ 来自: 220.134.27.68 (04/15 18:27)