System::Collections::Generic::Stack class
Contenuti
[
Nascondere
]Stack class
Stack class forward declaration.
template<typename T>class Stack : public System::Collections::Generic::IEnumerable<T>
| Parametro | Descrizione |
|---|---|
| T | Tipo di elemento. |
Nested classes
- Class Enumerator
Metodi
| Metodo | Descrizione |
|---|---|
| AddRange(IEnumerablePtr) | Inserisce gli elementi nello stack. |
| virtual Clear() | Elimina tutti gli elementi dallo stack. |
| virtual Contains(const T&) const | Verifica se un elemento specifico è presente nel contenitore; utilizza l’operatore == per il confronto. |
| data() | Accessor interno alla struttura dati. |
| data() const | Accessor interno alla struttura dati. |
| virtual get_Count() const | Ottiene il numero di elementi nello stack. |
| GetEnumerator() override | Ottiene l’enumeratore per iterare attraverso lo stack corrente. |
| Peek() | Ottiene l’elemento dalla cima dello stack, ma lo mantiene nello stack. |
| Pop() | Ottiene l’elemento dalla cima dello stack. |
| Push(const T&) | Inserisce l’elemento nella cima dello stack. |
| Stack() | Costruisce uno stack vuoto. |
| Stack(int) | Costruisce uno stack vuoto. |
| Stack(IEnumerablePtr) | Costruttore di copia. |
| virtual ToArray() | Converte lo stack in un array. |
| virtualizeBeginConstIterator() const override | Ottiene l’implementazione dell’iteratore const begin per il contenitore corrente. |
| virtualizeBeginIterator() override | Ottiene l’implementazione dell’iteratore begin per il contenitore corrente. |
| virtualizeEndConstIterator() const override | Ottiene l’implementazione dell’iteratore const end per il contenitore corrente. |
| virtualizeEndIterator() override | Ottiene l’implementazione dell’iteratore end per il contenitore corrente. |
Typedefs
| Typedef | Descrizione |
|---|---|
| IEnumerablePtr | Collezione contenente elementi dello stesso tipo. |
| IEnumeratorPtr | Enumerator tipo. |
| stack_t | Informazioni RTTI. |
| ValueType | Tipo valore. |
Osservazioni
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()
{
// Crea l'istanza della classe Stack.
auto stack = MakeObject<Stack<int>>();
// Riempie lo stack.
stack->Push(1);
stack->Push(2);
stack->Push(3);
// Stampa l'ultimo elemento dello stack. Il metodo Peek non rimuove alcun elemento dallo stack.
std::cout << stack->Peek() << std::endl;
PrintItems(stack);
// Stampa l'ultimo elemento dello stack. Il metodo Pop rimuove un elemento dallo 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
*/
Vedi anche
- Class IEnumerable
- Namespace System::Collections::Generic
- Library Aspose.Font for C++