<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS栈</title>
</head>
<body>
<script type="text/javascript">
function Stack(count){
var top=-1;//top头指针
this.myArray=new Array();
if(count!=undefined){
this.count=count;
this.myArray=new Array(this.count);
}else{
this.count=0;
}
//入栈
this.In=function(value){
if(top==this.count){
return false;
}else{
++top;
this.myArray[top]=value;
return true;
}
return false;
}
//出栈
this.Out=function(){
if(top==-1){
return false;
}else{
var removeValue=this.myArray[top];
this.myArray[top]=null;
top--;
return removeValue;
}
}
this.Clear=function(){
this.top=-1;
}
//遍历栈
this.tostring=function(){
for(var i=0;i<this.myArray.length;i++){
document.write(this.myArray[i]+'<br>');
}
}
}
Stack(3);
In(1);
In(2);
In(3);
tostring();//1 2 3
Out();
Out();
tostring();//1 null null
In(4);
tostring();//1 4 null
</script>
</body>
</html>
function Stack(count){
var top=-1;//top头指针
this.myArray=new Array();
if(count!=undefined){
this.count=count;
this.myArray=new Array(this.count);
}else{
this.count=0;
}
//入栈
this.In=function(value){
if(top==this.count){
return false;
}else{
++top;
this.myArray[top]=value;
return true;
}
return false;
}
//出栈
this.Out=function(){
if(top==-1){
return false;
}else{
var removeValue=this.myArray[top];
this.myArray[top]=null;
top--;
return removeValue;
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有