Commit 91127488 by Alan de Oliveira

comentando exercicio 2

parent 5605ae38
...@@ -55,16 +55,39 @@ class Fila { ...@@ -55,16 +55,39 @@ class Fila {
}; };
/**
* @brief Reescreva as operações de uma pilha utilizando uma fila
*
* As operações serão descritas abaixo
*
* @tparam T
*/
template <class T> template <class T>
class Pilha { class Pilha {
public: public:
/**
* @brief
* O empilhamento é o mesmo enfileiramento
*
* @param elemento
*/
void empilha(T elemento) { void empilha(T elemento) {
if (fila == nullptr) if (fila == nullptr)
fila = new Fila<T>(); fila = new Fila<T>();
fila->enfilera(elemento); fila->enfilera(elemento);
} }
/**
* @brief
* Para desempilhar, eu crio uma nova fila passo todos os elementos
* para ela, exceto o último elemento. e faço o delete na antiga fila.
*
* @return T
*/
T desempilha() { T desempilha() {
if (fila->frente() == -1) if (fila->frente() == -1)
...@@ -81,6 +104,9 @@ class Pilha { ...@@ -81,6 +104,9 @@ class Pilha {
return elemento; return elemento;
} }
T topo() {
return fila->frente();
}
private: private:
Fila<T> *fila = new Fila<T>(); Fila<T> *fila = new Fila<T>();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment