如何实现vbs栈类

发布时间:2021-10-11 09:38:36 作者:小新
来源:亿速云 阅读:97

这篇文章将为大家详细讲解有关如何实现vbs栈类,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。

数据结构的问题相当重要,如果你能描述出一个问题的输入和输出数据结构,那么这个问题就大有希望,数据结构并不是C语言的专利,真正的数据结构是伪代码的。下面这个栈类是我以前搜集别人的代码,实际上每当考虑一个程序问题的时候,尤其是复杂的程序,就应该想到,用什么样的数据去描述你的输入和输出。

'**********************************************
'        vbs栈类
'        push(string)进栈
'        getTop取栈顶元素
'        pop去掉栈顶元素
'        isempty是否栈空
'        isfull是否栈满(pMax设置了大小,可自行修改)
'**********************************************

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

关于“如何实现vbs栈类”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。

推荐阅读:
  1. 用栈实现队列和用队列实现栈
  2. Python怎么实现栈

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

vbs

上一篇:如何解决Debezium的坑

下一篇:如何实现对淘宝URL中ID提取的PHP代码

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》