def recursive_remove(S: ArrayStack): if S.is_empty(): pass else: S.pop() print(S._data) recursive_remove(S)
def kuo_hao_match(expr: str): """返回True 如果所有的delimiters 都前后正确匹配,反之返回False""" left = '([{' right = ')]}' happened = ArrayStack() for _chr in expr: if _chr in left: happened.push(_chr) elif _chr in right: if happened.is_empty(): return False if right.index(_chr) != left.index(happened.pop()): return False # 如果能顺利遍历排空所有happened,则返回True return happened.is_empty()
def reverse_list_by_stack(l: List, s: ArrayStack): for i in l: s.push(i) for i in range(len(l)): if s.is_empty(): break else: l[i] = s.pop() return l