Last active
March 1, 2020 14:27
-
-
Save divanibarbosa/ef654dcfc1c18dd4daf660a3b5b2996a to your computer and use it in GitHub Desktop.
Pilha em Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Criado por: profa. Divani Barbosa Gavinier | |
# Curriculo Lattes: http://lattes.cnpq.br/8503400830635447 | |
# divanibarbosa@gmail.com | |
def empty(pilha): #verifica se pilha está vazia | |
return len(pilha) == 0 | |
def push(pilha,item): #adiciona itens na pilha | |
pilha.append(item) | |
def pop(pilha): #remove itens da pilha | |
if empty(pilha): | |
print("ATENÇÃO PILHA VAZIA") | |
else: | |
item=pilha.pop() | |
return item | |
def top(pilha): #retorna item do topo sem remove-lo | |
if empty(pilha): | |
print("ATENÇÃO PILHA VAZIA") | |
else: | |
return pilha[len(pilha)-1] | |
def size(pilha): #retorna tamanho da pilha | |
return len(pilha) | |
p=[] #iniciando pilha | |
s=input() | |
for i in range(0,len(s),1): | |
push(p,s[i]) | |
for i in range(0,len(s),1): | |
print(pop(p), end="") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment