Skip to content

Instantly share code, notes, and snippets.

@trashw1n
trashw1n / general_trees2binary_trees.py
Created October 16, 2022 17:44 — forked from Shaunwei/general_trees2binary_trees.py
Encoding general trees as binary trees. There is a one-to-one mapping between general ordered trees and binary trees, which in particular is used by Lisp to represent general ordered trees as binary trees.
class TreeNode:
def __init__(self, label):
self.label = label
self.childrens = []
self.sibling = None
def __str__(self):
return 'Tree[' + str(self.label) + ']'
class BinaryTreeNode: