Tree
# tree - preordertree = [('a', [('b', [('d', []), ('e', [])]), ('c', [('f', [])])])] def preorder(tree):stack = [tree[0]]output = []while stack:value, children = stack.pop()output.append(value)stack.extend(reversed(children))return output print(preorder(tree)) # 결과['a', 'b', 'd', 'e', 'c', 'f'] # tree - preordertree = [('a', [('b', [('d', []), ('e', [])]), ('c', [('f', [])])])] from collections ..
Python
2016. 6. 12. 10:25