def verifierParentheses(fileReste): if est_vide(fileReste): return True (teteFile, fileReste) = pop(fileReste) stock = Pile(teteFile, Pile.pile_vide) while not est_vide(fileReste): (teteFile, fileReste) = pop(fileReste) if teteFile == ']': if Pile.est_vide(stock): return False else: (sommetPile, stock) = stock.pop() if sommetPile != '[': return False elif teteFile == ')': if Pile.est_vide(stock): return False else: (sommetPile, stock) = stock.pop() if sommetPile != '(': return False else: stock = stock.push(teteFile) return True
def copie(pileReste): if est_vide(pileReste): return pileReste tmp = pop(pileReste) return pile(tmp[0], copie(tmp[1]))
def min(pile): if est_vide(pile): return None tmp = pop(pile) if est_vide(tmp[1]): return tmp[0] resteMin = min(tmp[1]) if tmp[0] < resteMin: return tmp[0] else: return resteMin
def max(pile): if est_vide(pile): return None tmp = pop(pile) if est_vide(tmp[1]): return tmp[0] resteMax = max(tmp[1]) if tmp[0] > resteMax: return tmp[0] else: return resteMax
def verifierParentheses(fileReste): stock = pile_vide() while not est_vide(fileReste): (teteFile, fileReste) = pop(fileReste) if teteFile == ']': if est_vide(stock): return False else: (sommetPile, stock) = pop(stock) if sommetPile != '[': return False elif teteFile == ')': if est_vide(stock): return False else: (sommetPile, stock) = pop(stock) if sommetPile != '(': return False else: stock = push(teteFile, stock) return True
def fileStr(file): if est_vide(file): return 'x' else: tmp = pop(file) return '[' + str(tmp[0]) + ']-' + fileStr(tmp[1])
def taille(pile): if est_vide(pile): return 0 return 1 + taille(pop(pile)[1])
def pileStr(pile): if est_vide(pile): return 'x' else: tmp = pop(pile) return '[' + str(tmp[0]) + ']-' + pileStr(tmp[1])