System::Collections::Generic::Stack class
Contents
[
Hide
]Stack class
Stack class forward declaration.
template<typename T>class Stack : public System::Collections::Generic::IEnumerable<T>
Parameter | Description |
---|---|
T | Element type. |
Nested classes
- Class Enumerator
Methods
Method | Description |
---|---|
AddRange(IEnumerablePtr) | Puts elements into stack. |
virtual Clear() | Deletes all elements from stack. |
virtual Contains(const T&) const | Checks if specific item is present in container; uses operator == for comparison. |
data() | Internal data structure accessor. |
data() const | Internal data structure accessor. |
virtual get_Count() const | Gets number of elements in stack. |
GetEnumerator() override | Gets enumerator to iterate through current stack. |
Peek() | Gets element from stack top, but keeps it in stack. |
Pop() | Gets element from top of the stack. |
Push(const T&) | Puts element of top of the stack. |
Stack() | Constructs empty stack. |
Stack(int) | Constructs empty stack. |
Stack(IEnumerablePtr) | Copy constructor. |
virtual ToArray() | Converts stack to array. |
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 |
---|---|
IEnumerablePtr | Collection containing elements of same type. |
IEnumeratorPtr | Enumerator type. |
stack_t | RTTI information. |
ValueType | Value type. |
Remarks
Stack class wrapping std::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/stack.h>
#include <system/smart_ptr.h>
using namespace System;
using namespace System::Collections::Generic;
void PrintItems(const SmartPtr<IEnumerable<int>> &stack)
{
for (const auto item: stack)
{
std::cout << item << ' ';
}
std::cout << std::endl;
}
int main()
{
// Create the Stack-class instance.
auto stack = MakeObject<Stack<int>>();
// Fill the stack.
stack->Push(1);
stack->Push(2);
stack->Push(3);
// Print the last item of the stack. The Peek method doesn't remove an item from the stack.
std::cout << stack->Peek() << std::endl;
PrintItems(stack);
// Print the last item of the stack. The Pop method removes an item from the stack.
std::cout << stack->Pop() << std::endl;
PrintItems(stack);
return 0;
}
/*
This code example produces the following output:
3
3 2 1
3
2 1
*/
See Also
- Class IEnumerable
- Namespace System::Collections::Generic
- Library Aspose.PUB for C++