Skip to content

Instantly share code, notes, and snippets.

@Thiago4532
Created May 21, 2019 22:18
Show Gist options
  • Save Thiago4532/e1e42d19f6fd4c4a84d1ea99e22af662 to your computer and use it in GitHub Desktop.
Save Thiago4532/e1e42d19f6fd4c4a84d1ea99e22af662 to your computer and use it in GitHub Desktop.
#include <stack> // Biblioteca da stack
using namespace std;
int main() {
stack<int> pilha; // Declaro a stack do tipo int
pilha.push(1); // Insiro o elemento 1 no topo da pilha
pilha.push(3); // Insiro o elemento 3 no topo da pilha
pilha.push(7); // Insiro o elemento 7 no topo da pilha
pilha.push(10); // Insiro o elemento 10 no topo da pilha
while(!pilha.empty()) { // Enquanto a pilha nao estiver vazia
cout << pilha.top() << " "; // Imprime o elemento no topo da pilha
pilha.pop(); // Remove o elemento do topo.
}
cout << "\n";
// O algoritmo acima imprime todos os elementos da pilha do topo até o final
// Saída: 10 7 3 1
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment