本文整理汇总了C#中RedBlackTree.DrawTree方法的典型用法代码示例。如果您正苦于以下问题:C# RedBlackTree.DrawTree方法的具体用法?C# RedBlackTree.DrawTree怎么用?C# RedBlackTree.DrawTree使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RedBlackTree
的用法示例。
在下文中一共展示了RedBlackTree.DrawTree方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DoTest
public static void DoTest()
{
// Test against the worst case of insertion
// Case: insert increasing numbers and check if it leads to a linked list
var redBlackTree = new RedBlackTree<int>(allowDuplicates: false);
redBlackTree.Insert(1);
redBlackTree.Insert(2);
redBlackTree.Insert(3);
redBlackTree.Insert(4);
redBlackTree.Insert(5);
redBlackTree.Insert(6);
redBlackTree.Insert(7);
redBlackTree.Insert(8);
redBlackTree.Insert(9);
redBlackTree.Insert(10);
Debug.Assert(redBlackTree.Height < redBlackTree.Count, "Fail! Tree doesn't rebalance against sorted elements!");
Console.WriteLine("********************");
Console.WriteLine(" [*] RED-BLACK TREE:\r\n");
Console.WriteLine("********************");
Console.WriteLine(redBlackTree.DrawTree());
Console.WriteLine("\r\n");
//
// Test against re-shuffled insertions (not like above order)
redBlackTree = new RedBlackTree<int>(allowDuplicates: false);
redBlackTree.Insert(4);
redBlackTree.Insert(5);
redBlackTree.Insert(7);
redBlackTree.Insert(2);
redBlackTree.Insert(1);
redBlackTree.Insert(3);
redBlackTree.Insert(6);
redBlackTree.Insert(0);
redBlackTree.Insert(8);
redBlackTree.Insert(10);
redBlackTree.Insert(9);
//
// ASSERT INSERTING DUPLICATES WOULD BREAK
var insert_duplicate_passed = true;
try
{
// 2 already exists in tree
redBlackTree.Insert(2);
insert_duplicate_passed = true;
}
catch
{
insert_duplicate_passed = false;
}
Debug.Assert(insert_duplicate_passed == false, "Fail! The tree doesn't allow duplicates");
//
// PRINT TREE
Console.WriteLine("********************");
Console.WriteLine(" [*] RED-BLACK TREE:\r\n");
Console.WriteLine("********************");
Console.WriteLine(redBlackTree.DrawTree());
Console.WriteLine("\r\n");
// Assert count
Debug.Assert(redBlackTree.Count == 11);
// Assert existence and nonexistence of some items
Debug.Assert(redBlackTree.Contains(1) == true);
Debug.Assert(redBlackTree.Contains(3) == true);
Debug.Assert(redBlackTree.Contains(999) == false);
// ASSERT THAT EACH LEVEL HAS A DIFFERENT COLOR
Asset_Levels_Different_Colors(redBlackTree);
// Do some deletions
redBlackTree.Remove(7);
redBlackTree.Remove(1);
redBlackTree.Remove(3);
// Assert count
Debug.Assert(redBlackTree.Count == 8);
// Assert nonexistence of previously existing items
Debug.Assert(redBlackTree.Contains(1) == false);
Debug.Assert(redBlackTree.Contains(3) == false);
// Remove root value
var oldRootVal = redBlackTree.Root.Value;
redBlackTree.Remove(redBlackTree.Root.Value);
// Assert count
Debug.Assert(redBlackTree.Count == 7);
// Assert nonexistence of old root's value
Debug.Assert(redBlackTree.Contains(oldRootVal) == false);
//.........这里部分代码省略.........