Esempio n. 1
0
        public void CreateAdjacencyList(List <List <string> > edges)
        {
            AdjacencyList = new List <BinarySearchTreeNode>();
            var groupedEdges = ConvertEdgesToInts(edges).GroupBy(q => q[0]);

            foreach (var vertex in groupedEdges.SelectMany(q => q))
            {
                var tree = new BinarySearchTree();
                foreach (var item in vertex)
                {
                    tree.Insert(item);
                }
                AdjacencyList.Add(tree.root);
            }
        }
Esempio n. 2
0
        static void TestTree()
        {
            BinarySearchTree <int> tree = new BinarySearchTree <int>(5, null, null);

            tree.Insert(tree.GetRootNode(), -8);
            tree.Insert(tree.GetRootNode(), 10);
            tree.Insert(tree.GetRootNode(), 3);
            tree.Insert(tree.GetRootNode(), 8);
            tree.Insert(tree.GetRootNode(), 9);
            tree.Insert(tree.GetRootNode(), 0);
            Console.WriteLine(tree.FindMin(tree.GetRootNode()).data);
            tree.Print();
            tree.DeleteNode(10);
            tree.Print();
            //Console.WriteLine(tree.Search(tree.GetRootNode(), 9).data);
        }
 public static void Insert(long key, BinarySearchTreeNode root)
 {
     BinarySearchTree.Insert(key, root);
     Rebalance(root);
 }
Esempio n. 4
0
 public static BinarySearchTreeNode Insert(long key, BinarySearchTreeNode root)
 {
     BinarySearchTree.Insert(key, root);
     return(Find(key, root));
 }