TIPE/Python Files/modules.py

20 lines
608 B
Python
Raw Permalink Normal View History

2024-02-16 13:26:43 +01:00
class FP:
def __init__(self):
self.tab_elem = [] # elements
self.tab_prio = [] # priorité
def push(self, sommet, prio): #ajoute l'élément sommet a la file de priorité
self.tab_elem.append(sommet)
self.tab_prio.append(prio)
def pop(self): # sort l'élément de priorité minimale
indice = self.tab_prio.index(min(self.tab_prio))
elem = self.tab_elem[indice]
self.tab_prio.pop(indice)
self.tab_elem.pop(indice)
return(elem)
def is_empty(self):
return(len(self.tab_prio) == 0)