99re热这里只有精品视频,7777色鬼xxxx欧美色妇,国产成人精品一区二三区在线观看,内射爽无广熟女亚洲,精品人妻av一区二区三区

VB.Net - Queue隊列

2018-12-16 17:15 更新
Queue表示對象的先進(jìn)先出集合。 當(dāng)您需要項(xiàng)目的先進(jìn)先出訪問時使用。 當(dāng)您在列表中添加項(xiàng)目時,它被稱為enqueue,當(dāng)您刪除項(xiàng)目時,稱為deque。


隊列類的屬性和方法

下表列出了Queue類的一些常用屬性:

屬性描述
CountGets the number of elements contained in the Queue.
獲取隊列中包含的元素數(shù)。

下表列出了Queue類的一些常用方法:

S.N方法名稱和用途
1

Public Overridable Sub Clear

Removes all elements from the Queue.

從隊列中刪除所有元素。

2

Public Overridable Function Contains (obj As Object) As Boolean

Determines whether an element is in the Queue.

確定元素是否在隊列中。

3

Public Overridable Function Dequeue As Object

Removes and returns the object at the beginning of the Queue.

刪除并返回隊列開頭的對象。

4

Public Overridable Sub Enqueue (obj As Object)

Adds an object to the end of the Queue.

將對象添加到隊列的末尾。

5

Public Overridable Function ToArray As Object()

Copies the Queue to a new array.

將隊列復(fù)制到新數(shù)組。

6

Public Overridable Sub TrimToSize

Sets the capacity to the actual number of elements in the Queue.

將容量設(shè)置為隊列中實(shí)際的元素數(shù)。


示例:

以下示例演示如何使用隊列:
Module collections
   Sub Main()
      Dim q As Queue = New Queue()
      q.Enqueue("A")
      q.Enqueue("M")
      q.Enqueue("G")
      q.Enqueue("W")
      Console.WriteLine("Current queue: ")
      Dim c As Char
      For Each c In q
          Console.Write(c + " ")
      Next c
      Console.WriteLine()
      q.Enqueue("V")
      q.Enqueue("H")
      Console.WriteLine("Current queue: ")
      For Each c In q
          Console.Write(c + " ")
      Next c
      Console.WriteLine()
      Console.WriteLine("Removing some values ")
      Dim ch As Char
      ch = q.Dequeue()
      Console.WriteLine("The removed value: {0}", ch)
      ch = q.Dequeue()
      Console.WriteLine("The removed value: {0}", ch)
      Console.ReadKey()
   End Sub
End Module

當(dāng)上述代碼被編譯和執(zhí)行時,它產(chǎn)生以下結(jié)果:
Current queue: 
A M G W 
Current queue: 
A M G W V H 
Removing some values
The removed value: A
The removed value: M

以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號