Enqueue, Dequeue and Peek : Queue « Collections « VB.Net Tutorial

Home
VB.Net Tutorial
1.Language Basics
2.Data Type
3.Operator
4.Statements
5.Date Time
6.Class Module
7.Development
8.Collections
9.Generics
10.Attributes
11.Event
12.LINQ
13.Stream File
14.GUI
15.GUI Applications
16.Windows Presentation Foundation
17.2D Graphics
18.I18N Internationlization
19.Reflection
20.Regular Expressions
21.Security
22.Socket Network
23.Thread
24.Windows
25.XML
26.Database ADO.net
27.Design Patterns
VB.Net
VB.Net by API
VB.Net Tutorial » Collections » Queue 
8.26.2.Enqueue, Dequeue and Peek
Imports System
 Imports System.Collections
 Class Tester
     Public Sub Run( )
     End Sub 'Run

     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

     Shared Sub Main( )
         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 'Main
 End Class 'Tester
intQueue values:
0
5
10
15
20

(Dequeue) 0
intQueue values:
5
10
15
20

(Dequeue) 5
intQueue values:
10
15
20

(Peek)   10
intQueue values:
10
15
20
8.26.Queue
8.26.1.Queue
8.26.2.Enqueue, Dequeue and Peek
8.26.3.Queue.Enqueue and ToArray
8.26.4.Create a copy of the queue, using the ToArray method and the constructor that accepts an IEnumerable(Of T).
8.26.5.A queue can be enumerated without disturbing its contents.
8.26.6.Dequeuing,Peek and Dequeuing again
8.26.7.Copy the elements of the queue, starting at the middle of the array.
8.26.8.Queue.Contains
8.26.9.The Contains method is used to show that the string "four" is in the first copy of the queue
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.