本文整理汇总了C#中BinarySearchTree.Height方法的典型用法代码示例。如果您正苦于以下问题:C# BinarySearchTree.Height方法的具体用法?C# BinarySearchTree.Height怎么用?C# BinarySearchTree.Height使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BinarySearchTree
的用法示例。
在下文中一共展示了BinarySearchTree.Height方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DoTest
//.........这里部分代码省略.........
** / \
** 6 7
**
**************************************************************************
*/
avlTree.Insert(6); // insert
// ASSERT CASE 4
AssertCase_4(avlTree);
//
// CASE #5
// REMOVE the tree's root: 4.
//
/**************************************************************************
** UNBALANCED ===> TRANSITION (1st R) ===> BALANCED (2nd Rt)
** null .6..
** / \ / \
** 2 6 ===> ===> 2 7
** / \ / \ / \ /
** 1 3 5 7 1 3 5
**
**************************************************************************
*/
avlTree.Remove(avlTree.Root.Value); // REMOVE 4
// ASSERT CASE 5
AssertCase_5(avlTree);
//
// CLEAR THE TREE AND START OVER
// Compare two binary trees with each other (height-wise) using bulk-inserts
avlTree = new AVLTree<int>();
var bsTree = new BinarySearchTree<int>();
List<int> treeDataList = new List<int>() { 15, 25, 5, 12, 1, 16, 20, 9, 9, 7, 7, -1, 11, 19, 30, 8, 10, 13, 28, 39 };
avlTree.Insert(treeDataList);
bsTree.Insert(treeDataList);
int avlTreeHeight = avlTree.Height();
int bsTreeHeight = bsTree.Height();
Debug.Assert(avlTreeHeight < bsTreeHeight, "Wrong heights. AVL Tree must be shorted than BS Tree.");
//
// Draw the tree to the console.
Console.WriteLine(String.Format("************\r\n** BST TREE:\r\n************\r\n"));
Console.WriteLine(bsTree.DrawTree());
Console.WriteLine("\r\n\r\n");
Console.WriteLine(String.Format("************\r\n** AVL TREE:\r\n************\r\n"));
Console.WriteLine(avlTree.DrawTree());
//
// OUTPUT OF AVL TREE DRAWER
/*****
** ************
** ** AVL TREE:
** ************
** ....15...
** / \
** ...9.. ..20.
** / \ / \
** ..5. 11 16 28
** / \ / \ / \ / \
** 1 7 9 12 19 25 30
** /\ / \ / \ / \ /\ /\ / \
** -1 7 8 10 13 39
** /\ /\ /\ /\ /\ /\
*
*/
treeDataList = new List<int>() { 15, 25, 5, 12, 1, 9, 7, -1, 11, 30, 8, 10, 13, 28, 39 };
avlTree.Clear();
avlTree.Insert(treeDataList);
Console.WriteLine(String.Format("************\r\n** AVL TREE:\r\n************\r\n"));
Console.WriteLine(avlTree.DrawTree());
//
// OUTPUT OF AVL TREE DRAWER
/*****
**
** .......9......
** / \
** .5 ....12...
** / \ / \
** 1 7 11 .25.
** /\ / \ /\ / \
** -1 8 10 15 30
** /\ /\ /\ /\ / \
** 13 28 39
** /\ /\ /\
**
*/
Console.ReadLine();
}