public void ThreadedList() { treenode node = root; while (node != null) { while (node?.lefttype == 0) { node = node.left; } Console.WriteLine(node.id); while (node.righttype == 1) { node = node.right; Console.WriteLine(node.id); } node = node.right; } }
static void Main(string[] args) { treenode t1 = new treenode(1, "1"); treenode t3 = new treenode(3, "3"); treenode t6 = new treenode(6, "6"); treenode t8 = new treenode(8, "8"); treenode t10 = new treenode(10, "10"); treenode t14 = new treenode(14, "14"); t1.left = t3; t1.right = t6; t3.left = t8; t3.right = t10; t6.left = t14; InfixThreadedBinaryTree infixThreadedBinaryTree = new InfixThreadedBinaryTree(t1); infixThreadedBinaryTree.ThreadNode(); //treenode aaa = t10.left; //treenode bbb = t10.right; infixThreadedBinaryTree.ThreadedList(); Console.Read(); }
public void ThreadNode(treenode node) { if (node == null) { return; } ThreadNode(node.left); if (node.left == null) { node.left = pre; node.lefttype = 1; } if (pre != null && pre.right == null) { pre.right = node; pre.righttype = 1; } pre = node; ThreadNode(node.right); }
public InfixThreadedBinaryTree(treenode root) { this.root = root; }