在visualbasic6中实现循环队列

时间:2012-05-11 15:56:37

标签: vb6

 Public Function insert(x As Integer)
    If front = 0& & rear = n - 1 Or rear + 1 = front Then
     MsgBox "queue FULL !!!", vbOKOnly, "QUEUE"
    ElseIf front = -1 Then
     front = rear = 0
    ElseIf rear = n - 1 Then
     rear = 0
    Else
     rear = rear + 1
    End If
    arr(rear) = x
    MsgBox x, vbOKOnly, "INSERTED"
    List1.AddItem x
End Function

这是循环队列的insert()。我收到错误“如果前= 0&&后= n - 1或后+ 1 =前然后”
错误是“运行时错误'13'类型不匹配”。

2 个答案:

答案 0 :(得分:1)

我认为你的意思是

If front = 0& & rear = n - 1 Or rear + 1 = front Then

 If front = 0 And rear = n - 1 Or rear + 1 = front Then

你可能真的意味着

If (front = 0 And rear = n - 1) Or rear + 1 = front Then

你在混合你的“x”和“n”

答案 1 :(得分:0)

这也是错误的

front = rear = 0 

应该是

front = 0 
rear = 0 

=在VB6中具有两个含义

  • =是等于运算符,与c语言中的==相同
  • =也是赋值语句,就像c语言中的=运算符一样