大头锻炼日记4 -- vbscript中的栈Stack


vbscript能实现链式链表和静态链表就可以很方便的实现栈。栈一样分为链式栈和静态栈。

以下为静态栈的类主体代码: 
Option Explicit
' --------------------------------------
'         by.Shine
' --------------------------------------
Class Stack   '
     Private  Data( 10)     ' 10
     Private Top          '
    
     Public Sub  Class_Initialize      '
         Top = -1
     End  Sub
    
     Public Sub  Push(elem)        '
          If Top =( 10-1Then       '
               MsgBox  " Stack is full" 
               Exit Sub
          Else
              Top =Top + 1
               Data(Top) =elem
          End If
     End  Sub
     Public  Function Pop          '
          If IsRaw = True  Then       '
               MsgBox  " Stack is empty" 
               Exit Function
          Else
              Pop = Data(Top)
              Top =Top -1
          End If
     End Function
     Public  Function  GetTop       '
          If IsRaw = True  Then
               MsgBox  " Stack is empty" 
               Exit Function
          Else            
               GetTop = Data(Top)
          End If
     End Function
     Public  Function IsRaw        '
          If Top  >  -1  Then 
              IsRaw = False
          Else
              IsRaw = True
          End If
     End Function
     Public  Function StackLength  '
         StackLength =Top + 1
     End Function
     Public Sub  Clear             '
         Top = -1
     End  Sub
End  Class
 
以下为类实例测试代码:
' ------------------------------- 
'        
' -------------------------------    
Dim TestST,i,str                         '    
Set TestST = New Stack                     '
MsgBox TestST.IsRaw                      '
MsgBox TestST.StackLength                '
TestST.Push  " TESTTING"                   '
TestST. Clear                             '
TestST.Push  " U"                          '
TestST.Push  " O"
TestST.Push  " Y"
TestST.Push  " E"
TestST.Push  " V"
TestST.Push  " O"
TestST.Push  " L"
TestST.Push  " I"
MsgBox TestST. GetTop                     '
MsgBox TestST.IsRaw                      '
MsgBox TestST.StackLength                '
str = " "
For i = 1  To  8 Step  1
    str =str &TestST.Pop & "  "               '
Next
MsgBox str                               '
MsgBox TestST.IsRaw                      '
MsgBox TestST.StackLength                '

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值