# VB.Net program to implement Linear Queue using Structure

Here, we are going to learn how to implement Linear Queue using Structure in VB.Net?
Submitted by Nidhi, on January 15, 2021 [Last updated : March 08, 2023]

## VB.Net – Linear Queue using Structure

Here, we will implement a Linear Queue using Array and Structure. Linear Queue follows FIFO (First In First Out) property, which means first inserted elements, deleted first. In linear queue there are two pointers are used:

1. FRONT: It points to the location from where we can delete an item from the linear queue.
2. REAR: It points to the location from where we can insert the element into the linear queue.

Program/Source Code:

The source code to implement Linear Queue using Structure is given below. The given program is compiled and executed successfully.

## VB.Net code to implement Linear Queue using Structure

```'VB.Net program to implement Linear Queue using Structure.

Imports System.IO

Module Module1
Structure LinearQueue
Private ele() As Integer
Private front As Integer
Private rear As Integer
Private max As Integer

Public Sub New(ByVal size As Integer)
ReDim ele(size)
front = 0
rear = -1
max = size
End Sub

Public Sub insert(ByVal item As Integer)
If (rear = max - 1) Then
Console.WriteLine("Queue Overflow")
Else
rear = rear + 1
ele(rear) = item
End If
End Sub

Public Function delete() As Integer
Dim item As Integer = 0

If (front = rear + 1) Then
Console.WriteLine("Queue is Empty")
Return -1
Else
item = ele(front)
Console.WriteLine("deleted element is: " & item)
front = front + 1
Return item
End If

End Function

Public Sub printQueue()
If (front = rear + 1) Then
Console.WriteLine("Queue is Empty")
Else
For i = front To rear Step 1
Console.WriteLine("Item[" & (i + 1) & "]: " & ele(i))
Next
End If
End Sub
End Structure

Sub Main()
Dim Q As New LinearQueue(5)

Q.insert(10)
Q.insert(20)
Q.insert(40)
Q.insert(45)
Q.insert(66)

Console.WriteLine("Items are : ")
Q.printQueue()

Q.delete()
Q.delete()

Console.WriteLine("Items are : ")
Q.printQueue()
End Sub
End Module
```

## Output

```Items are :
Item[1]: 10
Item[2]: 20
Item[3]: 40
Item[4]: 45
Item[5]: 66
deleted element is: 10
deleted element is: 20
Items are :
Item[3]: 40
Item[4]: 45
Item[5]: 66
Press any key to continue . . .
```

## Explanation

In the above program, we created a module Module1 that contains the Main() function. The Main() function is the entry point for the program, Here, we created a structure LinearQueue that contains a default constructor and insert(), delete(), and printQueue() functions.

Here, default constructor is used to initializing the members of the LinearQueque structure. The insert() function is used to insert the item into the queue. The delete() function is used to remove the item from the queue, and the printQueue() function is used to print the item of the linear queue on the console screen.