Esempio n. 1
0
 public Node(double key, int level, int number)
 {
     Key = key;
     Level = level;
     Number = number;
     Left = Right = null;
 }
Esempio n. 2
0
 public BinarySearchTree()
 {
     Root = null;
 }
Esempio n. 3
0
 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);
 }
Esempio n. 4
0
 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);
 }
Esempio n. 5
0
 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;
 }
Esempio n. 6
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);
 }
Esempio n. 7
0
 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;
 }
Esempio n. 8
0
 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 "";
 }
Esempio n. 9
0
 public void ReadFromFile()
 {
     var formatter = new BinaryFormatter();
     using (var stream = File.Open("tree.bin", FileMode.Open))
     {
         Root = (Node)formatter.Deserialize(stream);
     }
 }