fahadkalil

fila_encadeada_12042021

Apr 12th, 2021 (edited)
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.83 KB | None | 0 0
  1. # implementacao de fila usando LSE
  2. from lse import LSE, Nodo
  3.  
  4. class FilaEncadeada:    
  5.     def __init__(self):
  6.         self.lista = LSE()
  7.  
  8.     def enqueue(self, item): # enfileirar
  9.         self.lista.inserir_fim(Nodo(item))
  10.  
  11.     def dequeue(self): # desenfileirar
  12.         if not self.lista.is_empty():
  13.             return self.lista.remover_inicio()
  14.  
  15.     def front(self): # verificar qual item esta no comeco
  16.         if not self.lista.is_empty():
  17.             return self.lista.head.dado
  18.  
  19.     def is_empty(self): # verifica se vazio
  20.         return self.lista.is_empty()
  21.  
  22.     def __len__(self): # retorna qtde itens
  23.         return len(self.lista)
  24.  
  25. ## TESTE ##
  26. '''
  27. f = FilaEncadeada()
  28. f.enqueue("A")
  29. f.enqueue("B")
  30. f.enqueue("C")
  31.  
  32. print(f.front()) # retorna A
  33. print(f.dequeue()) # retorna A
  34.  
  35. print(len(f))
  36. '''
  37.  
  38.  
  39.  
  40.  
  41.  
  42.    
  43.  
Add Comment
Please, Sign In to add comment