示例#1
0
        public void OrderStatisticTreeTests_Random_FindTheKthLargestNode()
        {
            Random r = new Random();
            int    n = r.Next(10000) + 1;

            IOrderStatisticTree <int, string>           tree = new OrderStatisticTree <int, string>();
            List <IBinarySearchTreeNode <int, string> > list = new List <IBinarySearchTreeNode <int, string> >();

            for (int i = 0; i < n; i++)
            {
                int key = r.Next(int.MaxValue);
                list.Add(tree.Insert(key, string.Empty));
            }

            list.Sort(new Comparison <IBinarySearchTreeNode <int, string> >((x, y) => y.Key.CompareTo(x.Key)));

            for (int i = 0; i < n / 2; i++)
            {
                int request = r.Next(i);

                var expectedNode = list[request];

                var actualNode = tree.FindTheKthLargestNode(request);

                Assert.IsNotNull(actualNode);
                Assert.AreEqual(expectedNode, actualNode);
            }
        }
        public void OrderStatisticTreeTests_Random_FindTheKthLargestNode()
        {
            Random r = new Random();
            int n = r.Next(10000) + 1;

            IOrderStatisticTree<int, string> tree = new OrderStatisticTree<int, string>();
            List<IBinarySearchTreeNode<int, string>> list = new List<IBinarySearchTreeNode<int, string>>();
            for (int i = 0; i < n; i++)
            {
                int key = r.Next(int.MaxValue);
                list.Add(tree.Insert(key, string.Empty));
            }

            list.Sort(new Comparison<IBinarySearchTreeNode<int, string>>((x, y) => y.Key.CompareTo(x.Key)));

            for (int i = 0; i < n / 2; i++)
            {
                int request = r.Next(i);

                var expectedNode = list[request];

                var actualNode = tree.FindTheKthLargestNode(request);

                Assert.IsNotNull(actualNode);
                Assert.AreEqual(expectedNode, actualNode);
            }
        }