数据结构的问题相当重要,如果你能描述出一个问题的输入和输出数据结构,那么这个问题就大有希望,数据结构并不是c语言的专利,真正的数据结构是伪代码的。下面这个栈类是我以前搜集别人的代码,实际上每当考虑一个程序问题的时候,尤其是复杂的程序,就应该想到,用什么样的数据去描述你的输入和输出。
'**********************************************
' vbs栈类
' push(string)进栈
' gettop取栈顶元素
' pop去掉栈顶元素
' isempty是否栈空
' isfull是否栈满(pmax设置了大小,可自行修改)
'
' 木鸟 2002.10.10
' http://www.51sjk.com/Upload/Articles/1/0/261/261327_20210702000034966.jpg
'**********************************************
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
用户登录
还没有账号?立即注册
用户注册
投稿取消
文章分类: |
|
还能输入300字
上传中....