大头锻炼日记6 -- vbscript中循环队列Queue


   坚持最重要,继续。
    队列(Queue),FIFO。 顺序存储结构的队列需要规避地址越界和假溢出,一般采用循环队列模式且头尾指针不重叠。
vbscript使用数组实现循环队列的方法。

创建队列类,主体代码如下: 
Option Explicit
' --------------------------------------
'         by.Shine
'   1.
'        (rear+1)QueueSizefrontindex
'   2.
'        (rear-front+QueueSize)QueueSize
' --------------------------------------
Class SqQueue 
     Private  Data( 10)     ' 10
     Private front        '
     Private rear         '
    
     Public Sub  Class_Initialize      '
         letFront = 0           '
         letRear = 0            '
     End  Sub
     Private Property  Let  letFront(e)         ' SET
         front =
     End Property
     Private Property  Let  letRear(e)      ' SET
         rear =
     End Property
     Public Property  Get getFront         ' GET
         getFront =front
     End Property
     Public Property  Get getRear          ' GET
         getRear =rear
     End Property
    
     Public  Function InitQueue            '
              letFront = 0
              letRear = 0
              InitQueue = True
     End Function
              
     Public  Function QueueLength                         '
         QueueLength =((getRear -getFront + 10Mod  10)      ' 2,10
     End Function
    
     Public Sub  InQueue(elem)                        '
          If IsFull = True  Then                         '
               MsgBox  " Queue is full"
               Exit Sub
          Else
               Data(getRear) =elem                       '
              letRear =((getRear + 1Mod  10)             '
          End If
     End  Sub
    
     Public  Function DeQueue
          If IsRaw = True  Then                           '
               MsgBox  " Queue is empty"
               Exit Function           
          Else
              DeQueue = Data(getFront)                   '
              letFront =((getFront + 1Mod  10)           '
          End If
     End Function
    
     Public  Function IsRaw                            '
          If getFront =getRear  Then
              IsRaw = True
          Else
              IsRaw = False
          End If
     End Function
    
     Public  Function IsFull                           '            '
          If ((getRear + 1Mod  10) =getFront  Then
              IsFull = True
          Else
              IsFull = False
          End If
     End Function    
End  Class

 以下为类实例测试代码:
 
' ------------------------------- 
'        
' ------------------------------- 
Dim TestSQ,i,str                             '    
Set TestSQ = New SqQueue                       '
MsgBox TestSQ.IsRaw                              '
MsgBox TestSQ.IsFull                             '
MsgBox  " Queue length is " &TestSQ.QueueLength     '
TestSQ.InQueue  " I"                               '
TestSQ.InQueue  " L"
TestSQ.InQueue  " O"
TestSQ.InQueue  " V"
TestSQ.InQueue  " E"
TestSQ.InQueue  " Y"
TestSQ.InQueue  " O"
TestSQ.InQueue  " U"  
MsgBox TestSQ.IsRaw                              '
MsgBox  " Queue length is " &TestSQ.QueueLength     '
str = " "
For i = 1  To TestSQ.QueueLength Step  1
    str =str &TestSQ.DeQueue & "  "                   '
Next
MsgBox str                                       ' FIFO
TestSQ.InitQueue                                 '
MsgBox TestSQ.IsRaw                              '
MsgBox TestSQ.IsFull                             '
MsgBox  " Queue length is " &TestSQ.QueueLength     '

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值