顺序队列

新建模块

Option Explicit

 

Public Const MaxSize As Integer = 10

 

Public Type SeqQueue

data(0 To MaxSize – 1) As Integer

length As Integer

End Type

‘队列初始化

Public Sub initQueue(q As SeqQueue)

q.length = 0

End Sub

 

‘进队

Public Sub enQueue(q As SeqQueue, e As Integer)

q.data(q.length) = e

q.length = q.length + 1

End Sub

 

‘出队

Public Function deQueue(q As SeqQueue) As Integer

Dim temp As Integer

temp = q.data(0)

Dim i As Integer

For i = 0 To q.length – 1

q.data(i) = q.data(i + 1)

Next i

q.length = q.length – 1

deQueue = temp

End Function

演示程序

Option Explicit

 

Dim q As SeqQueue

 

Private Sub CommandButton1_Click()

enQueue q, 123

End Sub

 

Private Sub CommandButton2_Click()

MsgBox deQueue(q)

End Sub

 

Private Sub UserForm_Click()

initQueue q

End Sub

 

2021年3月18日

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注