Queue data structure in VB.net

By: Issac Emailed: 1784 times Printed: 2624 times    

Another important data structure in .net is Queue, it works with the FIFO mechanism, like a linear pipe where water enters one side and exits the other side, the item enqueued first will be dequeued first.

Common functions of Queue

Enqueue : Add an Item in Queue 
Syntax : Stack.Enqueue(Object)
Object : The item to add in Queue 
Dequeue : Remove the oldest item from Queue (we dont get the item later) 
Syntax : Stack.Dequeue()
Returns : Remove the oldest item and return. 
Peek : Get the reference of the oldest item (it is not removed permenantly) 
Syntax : Stack.Peek()
returns : Get the reference of the oldest item in the Queue 

Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object,_
ByVal e As System.EventArgs) Handles Button1.Click
Dim queueList As New Queue
If queueList.Contains("1") Then
MsgBox("Contains 1 ")
MsgBox("Not Contains 1 ")
End If
End Sub
End Class

When the source code is executed it adds 7 items to the Queue, then dequeues the first item (“1”) in the queue, then peeks the oldest item in the queue(i.e “2” since “1” has been removed), then checks whether the queue contains “1” and shows the msg “Not Contains”

Most Viewed Articles (in VB.net )

Latest Articles (in VB.net)

Comment on this tutorial