GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — algorithms/tree/bintree2list.py at master · deba999/algorithms Expand file tree/ Copy pathbintree2list.pyMore file actions 53 lines (44 loc) · 1.03 KB / Copy pathbintree2list.pyFile metadata and controls53 lines (44 loc) · 1.03 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 class Node(): def __init__(self, val=0): self.val = val self.left = None self.right = None def bintree2list(root): """ type root: root class """ if not root: return root root = bintree2list_util(root) while root.left: root = root.left return root def bintree2list_util(root): if not root: return root if root.left: left = bintree2list_util(root.left) while left.right: left = left.right left.right = root root.left = left if root.right: right = bintree2list_util(root.right) while right.left: right = right.left right.left = root root.right = right return root def print_tree(root): while root: print(root.val) root = root.right tree = Node(10) tree.left = Node(12) tree.right = Node(15) tree.left.left = Node(25) tree.left.left.right = Node(100) tree.left.right = Node(30) tree.right.left = Node(36) head = bintree2list(tree) print_tree(head) |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |