System::Collections::Generic::Queue class
Contents
[
Hide
]Queue class
Queue class forward declaration.
template<typename T>class Queue : public System::Collections::Generic::IEnumerable<T>
| Parameter | Description |
|---|---|
| T | Element type. |
Nested classes
- Class Enumerator
Methods
| Method | Description |
|---|---|
| virtual Clear() | Deletes all elements in queue. |
| virtual Contains(const T&) const | Checks if queue contains specific element using operator == to compare elements. |
| data() | Underlying data structure accessor. |
| data() const | Underlying data structure accessor. |
| Dequeue() | Gets item from the beginning of the queue. |
| Enqueue(const T&) | Puts item to the end of the queue. |
| virtual get_Count() const | Gets number of elements in queue. |
| GetEnumerator() override | Gets enumerator to iterate through the queue. |
| Peek() | Gets item from the beginning of the queue, but does not remove it from queue. |
| Queue() | Constructs empty queue. |
| Queue(int) | Constructs empty queue. |
| Queue(const SharedPtr<IEnumerable<T>>&) | Copy constructor. |
| virtualizeBeginConstIterator() const override | Gets the implementation of begin const iterator for the current container. |
| virtualizeBeginIterator() override | Gets the implementation of begin iterator for the current container. |
| virtualizeEndConstIterator() const override | Gets the implementation of end const iterator for the current container. |
| virtualizeEndIterator() override | Gets the implementation of end iterator for the current container. |
Typedefs
| Typedef | Description |
|---|---|
| ValueType | This type. |
| queue_t | RTTI information. |
| IEnumerablePtr | Container of same type elements. |
| IEnumeratorPtr | Enumerator type. |
Remarks
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()
{
// Create the Queue-class instance.
auto queue = MakeObject<Queue<int>>();
// Fill the queue.
queue->Enqueue(1);
queue->Enqueue(2);
queue->Enqueue(3);
// Print the first queue item. The Peek method doesn't remove an item from the queue.
std::cout << queue->Peek() << std::endl;
// Print the queue items.
PrintItems(queue);
// Print the first queue item. The Dequeue method removes an item from the queue.
std::cout << queue->Dequeue() << std::endl;
// Print the queue items.
PrintItems(queue);
return 0;
}
/*
This code example produces the following output:
1
1 2 3
1
2 3
*/
See Also
- Class IEnumerable
- Namespace System::Collections::Generic
- Library Aspose.PUB for C++