0% found this document useful (0 votes)
41 views1 page

Circular Queue

The document contains a Visual Basic module for implementing a circular queue with basic operations such as Enqueue, Dequeue, and PrintQueue. It maintains a fixed-size array for storing elements and uses pointers to manage the front and end of the queue. The module includes checks for queue overflow and underflow conditions.

Uploaded by

Muhammad Haris
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views1 page

Circular Queue

The document contains a Visual Basic module for implementing a circular queue with basic operations such as Enqueue, Dequeue, and PrintQueue. It maintains a fixed-size array for storing elements and uses pointers to manage the front and end of the queue. The module includes checks for queue overflow and underflow conditions.

Uploaded by

Muhammad Haris
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Imports System.

Console

Module CircularQueue
Dim Queue(5) As Integer
Dim FrontQueuePointer As Integer = -1
Dim EndQueuePointer As Integer = -1
Dim MaxElements As Integer = 6
Dim QueueLength As Integer = 0

Sub Enqueue(ByVal Value As Integer)


If QueueLength >= MaxElements Then
WriteLine("Queue is Full.")
Else
EndQueuePointer = EndQueuePointer + 1
If EndQueuePointer >= MaxElements Then
EndQueuePointer = 0
ElseIf FrontQueuePointer = -1 Then
FrontQueuePointer = 0
End If
Queue(EndQueuePointer) = Value
QueueLength = QueueLength + 1
WriteLine(Queue(EndQueuePointer) & " " & "is added to the Queue.")
End If
End Sub

Sub Dequeue()
If QueueLength = 0 Then
WriteLine("Queue is Empty.")
Else
FrontQueuePointer = FrontQueuePointer + 1
If FrontQueuePointer >= MaxElements Then
FrontQueuePointer = 0
End If
QueueLength = QueueLength - 1
WriteLine("Value removed from the Queue.")
End If
End Sub

Sub PrintQueue()
Dim StartIndex As Integer = FrontQueuePointer
If QueueLength = 0 Then
WriteLine("Queue is Empty.")
Else
WriteLine("Start")
For i As Integer = 0 To QueueLength - 1
WriteLine(Queue(StartIndex))
StartIndex = StartIndex + 1
If StartIndex >= MaxElements Then
StartIndex = 0
End If
Next
WriteLine("End")
End If
End Sub
End Module

You might also like