用js可以用array对象很容易的实现栈的功能,但在vbs中没有相应的功能,没办法,只有自己动手了:(
如果你的栈不了解请查看数据结构的相关内容。这个栈类是参照c++的栈类写的,用法一样。用这个类你也可以很方便的修改出队列的类:)
<%
**********************************************
vbs栈类
push(string)进栈
gettop取栈顶元素
pop去掉栈顶元素
isempty是否栈空
isfull是否栈满(pmax设置了大小,可自行修改)
木鸟 2002.10.10
http://www.aspsky.net/
**********************************************
class stack
private parr, pstring, pmax
private tab
private sub class_initialize()
tab=chr(9)
pmax=1000 最大容量
end sub
private sub class_terminate()
if isarray(parr) then
erase parr
end if
end sub
public function push(str)
if str<>"" and instr(str,tab)<1 and not isfull then
if isarray(parr) then
pstring=join(parr,tab)
end if
pstring=pstring & tab & str
parr=split(pstring,tab)
push=true
else
push=false
end if
end function
public function gettop()
if not isarray(parr)<0 then
gettop=null
else
if ubound(parr)<0 then
gettop=null
else
gettop=parr(ubound(parr))
end if
end if
end function
public function pop()
if not isarray(parr) then
pop=false
else
if ubound(parr)<0 then
pop=false
else
pstring=join(parr,tab)
pstring=left(pstring,instrrev(pstring,tab)-1)
parr=split(pstring,tab)
pop=true
end if
end if
end function
public function isempty()
if not isarray(parr) then
isempty=true
else
if ubound(parr)<0 then
isempty=true
else
isempty=false
end if
end if
end function
public function isfull()
if not isarray(parr) then
isfull=false
else
if ubound(parr)<pmax then
isfull=false
else
isfull=true
end if
end if
end function
end class
%>
