文档详情

VB.Net-Queue队列.pdf

发布:2017-07-25约2.1千字共3页下载文档
文本预览下载声明
VB.Net - Queue 队列 Queue表⽰对象的先进先出集合。 当您需要项⽬的先进先出访问时使⽤。 当您在列表 中添加项⽬时,它被称 enqueue ,当您删除项⽬时,称 deque 。 队列类的属性和⽅法 下表列出了Queue类的⼀些常⽤属性: 属性 描述 Count Gets the number of elements contained in the Queue . 获取队列中包含的元素数。 下表列出了Queue类的⼀些常⽤⽅法: S.N ⽅法名称和⽤途 Public Overridable Sub Clear 1 Removes all elements from the Queue . 从队列中删除所有元素。 Public Overridable Function Contains (obj As Object) As Boolean 2 Determines whether an element is in the Queue . 确定元素是否在队列中。 Public Overridable Function De ueue As Object 3 Removes and returns the object at the beginning of the Queue . 删除并返回队列开头的对象。 Public Overridable Sub En ueue (obj As Object) Adds an object to the end of the Queue . 将对象添加到队列的末尾。 Public Overridable Function ToArray As Object() 5 Copies the Queue to a new array . 将队列复制到新数组。 Public Overridable Sub TrimToSize 6 Sets the capacity to the actual number of elements in the Queue . 将容量设置 队列中实际的元素数。 ⽰例: 以下⽰例演⽰如何使⽤队列: Module collections Sub Main() Dim q As Queue = New Queue() q.Enqueue(A) q.Enqueue(M) q.Enqueue(G) q.Enqueue(W) Console.W iteLine(Cu ent queue: ) Dim c As Cha Fo Each c In q Console.W ite(c + ) Next c Console.W iteLine() q.Enqueue(V) q.Enqueue(H) Console.W iteLine(Cu ent queue: ) Fo Each c In q Console.W ite(c + ) Next c Console.W iteLine() Console.W iteLine(Removing some values ) Dim ch As Cha ch = q.Dequeue() Console.W iteLine(The emoved value: {0}, ch) ch = q.Dequeue() Console.W iteLine(The emoved value: {0}, ch) Console.ReadKey() End Sub End Module 当上述代码被编译和执⾏时,它产⽣以下结果: Cu ent queue: A M G W Cu ent queue: A M G W V H Removing some values The emoved value: A Th
显示全部
相似文档