public Node(double key, int level, int number) { Key = key; Level = level; Number = number; Left = Right = null; }
public BinarySearchTree() { Root = null; }
private void pre_order_traversal(ref Node node) { if (node != null && node.Left == null && node.Right == null) node.Key++; if (node.Left != null) pre_order_traversal(ref node.Left); if (node.Right != null) pre_order_traversal(ref node.Right); }
private void simple_add(ref Node node, double key, int level, int number) { if (node != null) { if (node.Key > key) simple_add(ref node.Left, key, level + 1, 2 * number + 1); else simple_add(ref node.Right, key, level + 1, 2 * number + 2); } else node = new Node(key, level, number); }
private void post_order_traversal(ref Node node) { if (node.Left != null) post_order_traversal(ref node.Left); if (node.Right != null) post_order_traversal(ref node.Right); if (node.Key < 0) node.Key = 0; }
private void in_order_traversal(ref Node node) { if (node.Left != null) in_order_traversal(ref node.Left); if (node.Key % 2 == 0) node.Key *= 2; if (node.Right != null) in_order_traversal(ref node.Right); }
private bool do_find(Node node, double key) { if (node.Key == key) return true; else if (node.Key < key && node.Right != null) return do_find(node.Right, key); else if (node.Key > key && node.Left != null) return do_find(node.Left, key); else return false; }
private string dfs(Node node, int level) { if (node != null) return dfs(node.Right, level + 1) + new String(' ', 4 * level) + node.ToString() + "\n" + dfs(node.Left, level + 1); else return ""; }
public void ReadFromFile() { var formatter = new BinaryFormatter(); using (var stream = File.Open("tree.bin", FileMode.Open)) { Root = (Node)formatter.Deserialize(stream); } }