System::Collections::Generic::Queue 类

Queue class

Queue class forward declaration.

template<typename T>class Queue : public System::Collections::Generic::IEnumerable<T>
参数描述
T元素类型。

Nested classes

方法

方法描述
virtual Clear()删除队列中的所有元素。
virtual Contains(const T&) const检查队列是否包含特定元素,使用运算符 == 来比较元素。
data()底层数据结构访问器。
data() const底层数据结构访问器。
Dequeue()获取队列开头的项。
Enqueue(const T&)将项放入队列末尾。
virtual get_Count() const获取队列中元素的数量。
GetEnumerator() override获取枚举器以遍历队列。
Peek()获取队列开头的项,但不从队列中移除它。
Queue()构造空队列。
Queue(int)构造空队列。
Queue(const SharedPtr<IEnumerable<T>>&)拷贝构造函数。
virtualizeBeginConstIterator() const override获取当前容器的 begin const 迭代器的实现。
virtualizeBeginIterator() override获取当前容器的 begin 迭代器的实现。
virtualizeEndConstIterator() const override获取当前容器的 end const 迭代器的实现。
virtualizeEndIterator() override获取当前容器的 end 迭代器的实现。

Typedefs

类型定义描述
IEnumerablePtr相同类型元素的容器。
IEnumeratorPtrEnumerator 类型。
queue_tRTTI 信息。
ValueType此类型。

备注

Queue container wrapping STL list. Objects of this class should only be allocated using System::MakeObject() function. Never create instance of this type on stack or using operator new, as it will result in runtime errors and/or assertion faults. Always wrap this class into System::SmartPtr pointer and use this pointer to pass it to functions as argument.

#include <system/collections/queue.h>
#include <system/smart_ptr.h>

using namespace System;
using namespace System::Collections::Generic;

void PrintItems(const SmartPtr<IEnumerable<int>> &queue)
{
  for (const int item: queue)
  {
    std::cout << item << ' ';
  }
  std::cout << std::endl;
}

int main()
{
  // 创建 Queue 类的实例。
  auto queue = MakeObject<Queue<int>>();

  // 填充队列。
  queue->Enqueue(1);
  queue->Enqueue(2);
  queue->Enqueue(3);

  // 打印队列的第一个项。Peek 方法不会从队列中移除项。
  std::cout << queue->Peek() << std::endl;
  // 打印队列项。
  PrintItems(queue);

  // 打印队列的第一个项。Dequeue 方法会从队列中移除项。
  std::cout << queue->Dequeue() << std::endl;
  // 打印队列项。
  PrintItems(queue);

  return 0;
}
/*
This code example produces the following output:
1
1 2 3
1
2 3
*/

另见