System::Collections::Generic::Queue 类
内容
[
隐藏
]Queue class
Queue class forward declaration.
template<typename T>class Queue : public System::Collections::Generic::IEnumerable<T>
| 参数 | 描述 |
|---|---|
| T | 元素类型。 |
Nested classes
- Class Enumerator
方法
| 方法 | 描述 |
|---|---|
| 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 | 相同类型元素的容器。 |
| IEnumeratorPtr | Enumerator 类型。 |
| queue_t | RTTI 信息。 |
| 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
*/
另见
- Class IEnumerable
- Namespace System::Collections::Generic
- Library Aspose.Font for C++