您好,登錄后才能下訂單哦!
這篇文章將為大家詳細(xì)講解有關(guān)如何實(shí)現(xiàn)vbs棧類,小編覺得挺實(shí)用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。
數(shù)據(jù)結(jié)構(gòu)的問題相當(dāng)重要,如果你能描述出一個問題的輸入和輸出數(shù)據(jù)結(jié)構(gòu),那么這個問題就大有希望,數(shù)據(jù)結(jié)構(gòu)并不是C語言的專利,真正的數(shù)據(jù)結(jié)構(gòu)是偽代碼的。下面這個棧類是我以前搜集別人的代碼,實(shí)際上每當(dāng)考慮一個程序問題的時候,尤其是復(fù)雜的程序,就應(yīng)該想到,用什么樣的數(shù)據(jù)去描述你的輸入和輸出。
'**********************************************
' vbs棧類
' push(string)進(jìn)棧
' getTop取棧頂元素
' pop去掉棧頂元素
' isempty是否???
' isfull是否棧滿(pMax設(shè)置了大小,可自行修改)
'**********************************************
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
關(guān)于“如何實(shí)現(xiàn)vbs棧類”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,使各位可以學(xué)到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。