Simple Demo for Queue: Enqueue, Dequeue and Peek : Queue « Data Structure « VB.Net

Home
VB.Net
1.2D
2.Application
3.Class
4.Data Structure
5.Data Types
6.Database ADO.net
7.Date Time
8.Development
9.Event
10.File Directory
11.Generics
12.GUI
13.Internationalization I18N
14.Language Basics
15.LINQ
16.Network Remote
17.Reflection
18.Security
19.Thread
20.Windows Presentation Foundation
21.Windows System
22.XML
23.XML LINQ
VB.Net Tutorial
VB.Net by API
VB.Net » Data Structure » QueueScreenshots 
Simple Demo for Queue: Enqueue, Dequeue and Peek
Simple Demo for Queue: Enqueue, Dequeue and Peek
  
Imports System
Imports System.Collections
 
Public Class MainClass

    Shared Sub Main(ByVal args As String())
             Dim intQueue As New Queue( )

             ' populate the array
             Dim As Integer
             For i = To 4
                 intQueue.Enqueue((i * 5))
             Next i

             ' Display the Queue.
             Console.WriteLine("intQueue values:")
             DisplayValues(intQueue)

             ' Remove an element from the queue.
             Console.WriteLine("(Dequeue) {0}", intQueue.Dequeue( ))

             ' Display the Queue.
             Console.WriteLine("intQueue values:")
             DisplayValues(intQueue)

             ' Remove another element from the queue.
             Console.WriteLine("(Dequeue) {0}", intQueue.Dequeue( ))

             ' Display the Queue.
             Console.WriteLine("intQueue values:")
             DisplayValues(intQueue)

             ' View the first element in the
             ' Queue but do not remove.
             Console.WriteLine("(Peek)   {0}", intQueue.Peek( ))

             ' Display the Queue.
             Console.WriteLine("intQueue values:")
             DisplayValues(intQueue)
    End Sub

    Public Shared Sub DisplayValues(ByVal myCollection As IEnumerable)
        Dim myEnumerator As IEnumerator = myCollection.GetEnumerator( )
        While myEnumerator.MoveNext( )
             Console.WriteLine("{0} ", myEnumerator.Current)
        End While
        Console.WriteLine( )
    End Sub 'DisplayValues

End Class

           
         
    
  
Related examples in the same category
1.Queue Demo: enqueue, dequeue and peekQueue Demo: enqueue, dequeue and peek
2.Queue Item CountQueue Item Count
3.Creates a queue of strings with default capacity and uses the Enqueue method to queue five strings.
4.The elements of the queue are enumerated, which does not change the state of the queue.
5.The Dequeue method is used to dequeue the first string.
6.The Peek method is used to look at the next item in the queue
7.The ToArray method is used to create an array and copy the queue elements to it
8.the array is passed to the Queue<(Of <(T>)>) constructor that takes IEnumerable<(Of <(T>)>)
9.CopyTo method is used to copy the array elements beginning at the middle of the array.
10.Create a second copy of the queue containing three null elements at the beginning.
11.Queue Class represents a first-in, first-out collection of objects.
w__w___w_.j___a___va__2___s._c__o___m___ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.