Vb中队列的特征有哪些???
发布网友
发布时间:2022-05-02 20:48
我来回答
共1个回答
热心网友
时间:2022-06-27 02:12
先进先出。我这里有一个VB循环队列类代码,我写一个车辆排队程序时用过。给贴过来,看对你有没有帮助。
Option Explicit
# '* ************************************************************** *
# '* 程序名称:Queue.cls
# '* 程序功能:一个VB循环队列类
# '* 作者:lyserver
# '* 联系方式:http://blog.csdn.net /lyserver
# '* ************************************************************** *
# 'Class Queue '在ASP、WSH、HTML的 VBScript脚本中使用时需加此句
# Dim m_Queue() ' 队列
# Dim m_RetQueue() '队列返回值
# Dim m_ReadIndex '列首偏移索引
# Dim m_WriteIndex '元素插入偏移索引
# Dim m_MaxLen ' 队列最大尺寸
#
# Private Sub Class_Initialize()
# m_ReadIndex = 0
# m_WriteIndex = 0
# m_MaxLen = 20 '队列默认大小为 20
# ReDim m_Queue(m_MaxLen - 1)
# End Sub
#
# Private Sub Class_Terminate()
# Erase m_Queue
# Erase m_RetQueue
# End Sub
#
# '获得队列大小
# Public Property Get MaxLen()
# MaxLen = m_MaxLen
# End Property
#
# '设置队列大小
# Public Property Let MaxLen(ByVal NewValue)
# If NewValue > 0 Then
# m_MaxLen = NewValue
# ReDim m_Queue(m_MaxLen)
# End If
# End Property
#
# '插入队列元素
# Public Sub Insert(ByVal v)
# If m_WriteIndex = m_MaxLen Then '队列已满,挤掉最先插入的元素
# m_WriteIndex = 0
# m_ReadIndex = (m_ReadIndex + 1) Mod m_MaxLen
# End If
# m_Queue(m_WriteIndex) = v
# m_WriteIndex = m_WriteIndex + 1
# End Sub
#
# '删除队列元素(按队列原则,实际上是删除最先插入的元素)
# Public Sub Delete()
# Dim vTemp
# m_Queue(m_ReadIndex) = vTemp '将此变量置为未初始化
# m_ReadIndex = (m_ReadIndex + 1) Mod m_MaxLen
# End Sub
#
# '清空队列
# Public Sub Clear()
# ReDim m_Queue(m_MaxLen)
# m_WriteIndex = 0
# m_ReadIndex = 0
# End Sub
#
# '获得队列数组
# Public Property Get GetQueue()
# Dim i, n
#
# n = 0
# ReDim m_RetQueue(m_MaxLen)
# For i = m_ReadIndex To m_MaxLen - 1
# If IsEmpty(m_Queue(i)) Then Exit For
# m_RetQueue(n) = m_Queue(i)
# n = n + 1
# Next
# For i = 0 To m_ReadIndex - 1
# If IsEmpty(m_Queue(i)) Then Exit For
# m_RetQueue(n) = m_Queue(i)
# n = n + 1
# Next
# GetQueue = m_RetQueue
# End Property
# 'End Class '在ASP、WSH、HTML的 VBScript脚本中使用时需加此句