Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Module Module1
- Structure CircularQueue
- Dim Rear As Integer
- Dim Front As Integer
- Dim Elements As String()
- End Structure
- Function IsEmpty(MyQueue As CircularQueue) As Boolean
- If MyQueue.Rear = -1 And MyQueue.Front = -1 Then
- Return True
- Else : Return False
- End If
- End Function
- Function IsFull(MyQueue As CircularQueue) As Boolean
- If MyQueue.Front = MyQueue.Rear + 1 Or
- MyQueue.Front = 0 And MyQueue.Rear = MyQueue.Elements.Length - 1 Then
- Return True
- Else : Return False
- End If
- End Function
- Function Peek(MyQueue As CircularQueue) As String
- If Not IsEmpty(MyQueue) Then
- Return MyQueue.Elements(MyQueue.Front)
- End If
- Return ""
- End Function
- Function Dequeue(ByRef MyQueue As CircularQueue) As String
- Dim RemovedElement As String = Peek(MyQueue)
- If IsEmpty(MyQueue) Then
- Console.WriteLine("Stack Underflow")
- ElseIf MyQueue.Rear = MyQueue.Front Then
- MyQueue.Rear = -1
- MyQueue.Front = -1
- ElseIf MyQueue.Front = MyQueue.Elements.Length - 1 Then
- MyQueue.Front = 0
- Else : MyQueue.Front += 1
- End If
- Return RemovedElement
- End Function
- Sub Main()
- Dim DocumentsToPrint As CircularQueue
- InitialiseQueue(DocumentsToPrint, 5)
- Enqueue(DocumentsToPrint, "Hello")
- Console.WriteLine(Peek(DocumentsToPrint))
- Console.ReadLine()
- End Sub
- Sub InitialiseQueue(ByRef MyQueue As CircularQueue, QueueSize As Integer)
- MyQueue.Rear = -1
- MyQueue.Front = -1
- ReDim MyQueue.Elements(QueueSize - 1)
- End Sub
- Sub Enqueue(ByRef MyQueue As CircularQueue, NewElement As String)
- If IsFull(MyQueue) Then
- Console.WriteLine("Stack Overflow")
- Exit Sub
- ElseIf IsEmpty(MyQueue) Then
- MyQueue.Rear = 0
- MyQueue.Front = 0
- ElseIf MyQueue.Rear = MyQueue.Elements.Length - 1 Then
- MyQueue.Rear = 0
- Else
- MyQueue.Rear += 1
- End If
- MyQueue.Elements(MyQueue.Rear) = NewElement
- End Sub
- End Module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement