Skip to content

Instantly share code, notes, and snippets.

@Thiago4532
Created May 21, 2019 22:18
Show Gist options
  • Save Thiago4532/ee62aa8a284de9063bb113575b90d7f1 to your computer and use it in GitHub Desktop.
Save Thiago4532/ee62aa8a284de9063bb113575b90d7f1 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
cout << pilha.top() << "\n"; // Retorna o valor 7
pilha.pop(); // Removo o topo da pilha
cout << pilha.top() << "\n"; // Retorna o valor 5
pilha.pop();
cout << pilha.top() << "\n"; // Retorna o valor 1
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment