96年全國高級中等學校工科技藝競賽電腦軟體設計第二題,
大家練習看看吧!
原始碼:http://down.gogobox.com.tw/t2329175/yq2m2 Dim Rear As Integer, Front As Integer, Ran As Integer, now As Integer, Qu(48) As Integer, i As Integer
Private Sub Cm3_Click()
End
End Sub
Private Sub Form_Activate()
now = 5
Queue(0).Left = 400
Queue(0).Top = 800
For i = 1 To 5
Load Queue(i)
With Queue(i)
.Left = 400 + i * 495
.Top = 800
.Visible = True
End With
Next
Rear = 5
Front = 4
Lr.Left = Queue(Rear).Left + 100
Lr.Top = Queue(Rear).Top + 500
Lf.Left = Queue(Front).Left + 100
Lf.Top = Queue(Front).Top + 500
Qu(4) = 35
Qu(5) = 128
Lastr = "Now,Queue has 2 Datas."
ShowNow
End Sub
Private Sub Add_Click()
If CanAdd(Qu(), now) = True Then
If Rear = Front And Qu(Rear) = 0 Then
Ran = 1 + Int(Rnd * 1000)
Lax = "Add " & Str(Ran)
Qu(Rear) = Ran
Else
Rear = Rear + 1
If Rear > now Then Rear = 0
Ran = 1 + Int(Rnd * 1000)
Lax = "Add " & Str(Ran)
Qu(Rear) = Ran
End If
Else
If now = 23 Then
Lax = "Queue is full."
Else
For i = now + 1 To now + 6
Load Queue(i)
With Queue(i)
.Left = 400 + i * 495
.Top = 800
.Visible = True
End With
Next
now = now + 6
If Front <> 0 Then
If Rear > Front And Rear < now - 6 Then
For i = now - 6 To Rear Step -1
Qu(i + 6) = Qu(i)
Qu(i) = 0
Next
Rear = Rear + 6
ElseIf Rear < Front Then
For i = now - 6 To Front Step -1
Qu(i + 6) = Qu(i)
Qu(i) = 0
Next
Front = Front + 6
End If
End If
Rear = Rear + 1
If Rear > now Then Rear = 0
Ran = 1 + Int(Rnd * 1000)
Lax = "Add " & Str(Ran)
Qu(Rear) = Ran
End If
End If
ShowNow
End Sub
Public Sub ShowNow()
For i = 0 To now
Queue(i).Cls
Queue(i).CurrentX = 80
Queue(i).CurrentY = 120
If Qu(i) <> 0 Then
Queue(i).Print Qu(i)
x = x + 1
End If
Next
Lr.Left = Queue(Rear).Left + 100
Lr.Top = Queue(Rear).Top + 500
Lf.Left = Queue(Front).Left + 100
Lf.Top = Queue(Front).Top - 200
If x > 1 Then
Lastr = "Now,Queue has " & Str(x) & " Datas."
ElseIf x = 1 Then
Lastr = "Now,Queue has 1 Data."
ElseIf x = 0 Then
Lastr = "Now,Queue has none."
End If
End Sub
Public Function CanAdd(Queue() As Integer, big As Integer) As Boolean
CanAdd = True
For i = 0 To big
If Queue(i) = 0 Then x = x + 1
Next
If x < 2 Then CanAdd = False
End Function
Public Function CanRomove(Queue() As Integer, big As Integer) As Boolean
CanRomove = False
For i = 0 To big
If Queue(i) <> 0 Then CanRomove = True
Next
End Function
Private Sub Romove_Click()
If CanRomove(Qu(), now) = True Then
Lax = "Romove " & Str(Qu(Front))
Qu(Front) = 0
If Front <> Rear Then
Front = Front + 1
If Front > now Then Front = 0
End If
Else
Lax = "Queue is empty."
End If
ShowNow
End Sub
公告版位
星落的瞬間!放棄的後悔是永遠!
- Jun 24 Tue 2008 12:52
環佇列(Circular Queue)運行系統(VB6)
全站熱搜
留言列表
發表留言