示例#1
0
 public void Insert(Trade trade)
 {
     Node newNode = new Node();
     newNode.item = trade;
     if (root == null)
         root = newNode;
     else
     {
         Node current = root;
         Node parent;
         while (true)
         {
             parent = current;
             if (trade.Price < current.item.Price)
             {
                 current = current.leftc;
                 if (current == null)
                 {
                     parent.leftc = newNode;
                     return;
                 }
             }
             else
             {
                 current = current.rightc;
                 if (current == null)
                 {
                     parent.rightc = newNode;
                     return;
                 }
             }
         }
     }
 }
示例#2
0
 static void Main(string[] args)
 {
     Tree theTree = new Tree();
     Random r = new Random(DateTime.Now.Millisecond);
     for (int i = 0; i < 20; i++)
     {
         Trade t = new Trade() { Price = r.Next(1, 100), Time = DateTime.Now };
         theTree.Insert(t);
     }
     //theTree.Insert(20);
     //theTree.Insert(25);
     //theTree.Insert(45);
     //theTree.Insert(15);
     //theTree.Insert(67);
     //theTree.Insert(43);
     //theTree.Insert(80);
     //theTree.Insert(33);
     //theTree.Insert(67);
     //theTree.Insert(99);
     //theTree.Insert(91);
     Console.WriteLine("Inorder Traversal : ");
     theTree.Inorder(theTree.ReturnRoot());
     Console.WriteLine(" ");
     Console.WriteLine();
     Console.WriteLine("Preorder Traversal : ");
     theTree.Preorder(theTree.ReturnRoot());
     Console.WriteLine(" ");
     Console.WriteLine();
     Console.WriteLine("Postorder Traversal : ");
     theTree.Postorder(theTree.ReturnRoot());
     Console.WriteLine(" ");
     Console.WriteLine(" ");
     theTree.print(theTree.ReturnRoot());
     Console.WriteLine(" ");
     Console.ReadLine();
 }