Last active
November 30, 2023 00:26
-
-
Save divanibarbosa/a56f18f6bf760690767072d8ee768512 to your computer and use it in GitHub Desktop.
Fila 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 size(fila): #retorna tamanho da fila | |
return len(fila) | |
def empty(fila): #verifica se fila está vazia | |
return len(fila) == 0 | |
def enqueue(fila,item): #adiciona itens na fila | |
fila.append(item) | |
def dequeue(fila): #remove itens da fila | |
if empty(fila): | |
print("ATENÇÃO FILA VAZIA") | |
else: | |
item=fila.pop(0) | |
return item | |
def front(fila): #retorna proximo item sem remove-lo | |
if empty(fila): | |
print("ATENÇÃO FILA VAZIA") | |
else: | |
return fila[0] | |
f=[] #iniciando fila | |
print("Inserindo 3 itens na fila") | |
enqueue(f,2.3) | |
enqueue(f,4.5) | |
enqueue(f,7.89) | |
print("Verificando se a fila esta vazia") | |
if empty(f): | |
print("FILA VAZIA "); | |
else: | |
print("Fila contem %d elementos" %size(f)) | |
print("Removendo um item da fila") | |
print("Item removido = %.2f" %dequeue(f)) | |
print("Proximo item = %.2f" %front(f)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment