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()
- Dim MaxLength As Integer
- 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) Mod MyQueue.MaxLength 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 Mod MyQueue.MaxLength)
- 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("Queue Underflow")
- ElseIf MyQueue.Rear = MyQueue.Front Then
- MyQueue.Rear = -1
- MyQueue.Front = -1
- Else : MyQueue.Front = (MyQueue.Front + 1) Mod MyQueue.MaxLength
- End If
- Return RemovedElement
- End Function
- Sub Main()
- Dim DocumentsToPrint As CircularQueue
- InitialiseQueue(DocumentsToPrint, 2)
- 'manipulate the print queue with any of
- 'these functions and procedures
- Console.ReadLine()
- End Sub
- Sub InitialiseQueue(ByRef MyQueue As CircularQueue, QueueSize As Integer)
- MyQueue.Rear = -1
- MyQueue.Front = -1
- ReDim MyQueue.Elements(QueueSize - 1)
- MyQueue.MaxLength = QueueSize
- End Sub
- Sub Enqueue(ByRef MyQueue As CircularQueue, NewElement As String)
- If IsFull(MyQueue) Then
- Console.WriteLine("Queue Overflow")
- Exit Sub
- ElseIf IsEmpty(MyQueue) Then
- MyQueue.Rear = 0
- MyQueue.Front = 0
- Else
- MyQueue.Rear = (MyQueue.Rear + 1) Mod MyQueue.MaxLength
- End If
- MyQueue.Elements(MyQueue.Rear) = NewElement
- End Sub
- Sub PrintCQueue(MyQueue As CircularQueue)
- If Not IsEmpty(MyQueue) Then
- Dim i As Integer = MyQueue.Front
- Do
- Console.WriteLine(MyQueue.Elements(i))
- If i = MyQueue.Rear Then
- Exit Sub
- End If
- i = (i + 1) Mod MyQueue.MaxLength
- Loop Until i = MyQueue.Front
- End If
- End Sub
- End Module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement