课程表

VB.Net基本教程

VB.Net高级教程

工具箱
速查手册

VB.Net - Queue队列

当前位置:免费教程 » 程序设计 » VB.Net
Queue表示对象的先进先出集合。 当您需要项目的先进先出访问时使用。 当您在列表中添加项目时,它被称为enqueue,当您删除项目时,称为deque。


队列类的属性和方法

下表列出了Queue类的一些常用属性:

属性描述
CountGets the number of elements contained in the Queue.
获取队列中包含的元素数。

下表列出了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.

将队列复制到新数组。

6

Public Overridable Sub TrimToSize

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

将容量设置为队列中实际的元素数。


示例:

以下示例演示如何使用队列:
  1. Module collections
  2. Sub Main()
  3. Dim q As Queue = New Queue()
  4. q.Enqueue("A")
  5. q.Enqueue("M")
  6. q.Enqueue("G")
  7. q.Enqueue("W")
  8. Console.WriteLine("Current queue: ")
  9. Dim c As Char
  10. For Each c In q
  11. Console.Write(c + " ")
  12. Next c
  13. Console.WriteLine()
  14. q.Enqueue("V")
  15. q.Enqueue("H")
  16. Console.WriteLine("Current queue: ")
  17. For Each c In q
  18. Console.Write(c + " ")
  19. Next c
  20. Console.WriteLine()
  21. Console.WriteLine("Removing some values ")
  22. Dim ch As Char
  23. ch = q.Dequeue()
  24. Console.WriteLine("The removed value: {0}", ch)
  25. ch = q.Dequeue()
  26. Console.WriteLine("The removed value: {0}", ch)
  27. Console.ReadKey()
  28. End Sub
  29. End Module

当上述代码被编译和执行时,它产生以下结果:
  1. Current queue:
  2. A M G W
  3. Current queue:
  4. A M G W V H
  5. Removing some values
  6. The removed value: A
  7. The removed value: M

转载本站内容时,请务必注明来自W3xue,违者必究。
 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号