Queue data structure in VB.net
By: Issac
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
queueList.Enqueue("1")
queueList.Enqueue("2")
queueList.Enqueue("3")
queueList.Enqueue("4")
queueList.Enqueue("5")
queueList.Enqueue("6")
queueList.Enqueue("7")
MsgBox(queueList.Dequeue())
MsgBox(queueList.Peek())
If queueList.Contains("1") Then
MsgBox("Contains 1 ")
Else
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â€
Comment on this tutorial
- Data Science
- Android
- AJAX
- ASP.net
- C
- C++
- C#
- Cocoa
- Cloud Computing
- HTML5
- Java
- Javascript
- JSF
- JSP
- J2ME
- Java Beans
- EJB
- JDBC
- Linux
- Mac OS X
- iPhone
- MySQL
- Office 365
- Perl
- PHP
- Python
- Ruby
- VB.net
- Hibernate
- Struts
- SAP
- Trends
- Tech Reviews
- WebServices
- XML
- Certification
- Interview
categories
Subscribe to Tutorials
Related Tutorials
Using Resume Next and Resume Line in VB.net
Using On Error GoTo 0 in VB.net
Getting an Exception's Number and Description in VB.net
Raising an Exception Intentionally in VB.net
Exception Filtering in the Catch Block in VB.net
Using Multiple Catch Statements in VB.net
Throwing an Exception in VB.net
Throwing a Custom Exception in VB.net
Changes in Controls from VB6 to VB.net
Unstructured Exception Handling in VB.net