本文整理汇总了C#中BinaryTree.Add方法的典型用法代码示例。如果您正苦于以下问题:C# BinaryTree.Add方法的具体用法?C# BinaryTree.Add怎么用?C# BinaryTree.Add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BinaryTree
的用法示例。
在下文中一共展示了BinaryTree.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DeleteTest
public void DeleteTest()
{
var tree = new BinaryTree<float>();
tree.Add(4.21f);
tree.Add(421);
tree.Add(42);
tree.Add(1);
tree.Add(1000.500f);
tree.Delete(4.21f);
Assert.IsFalse(tree.Contains(4.21f));
Assert.IsTrue(tree.Contains(421));
Assert.IsTrue(tree.Contains(42));
Assert.IsTrue(tree.Contains(1));
tree.Delete(421);
Assert.IsFalse(tree.Contains(421));
Assert.IsTrue(tree.Contains(1));
tree.Delete(1);
Assert.IsFalse(tree.Contains(1));
Assert.IsFalse(tree.Contains(421));
Assert.IsTrue(tree.Contains(42));
tree.Delete(42);
Assert.IsFalse(tree.Contains(42));
Assert.IsTrue(tree.Contains(1000.500f));
tree.Delete(1000.500f);
Assert.IsFalse(tree.Contains(1000.500f));
Assert.IsTrue(tree.IsEmpty());
}
示例2: Interface
public void Interface()
{
var rootBinaryTree = new BinaryTree<int>(5);
var child1 = new BinaryTree<int>(2);
var child2 = new BinaryTree<int>(3);
rootBinaryTree.Add(child1);
rootBinaryTree.Add(child2);
var child4 = new BinaryTree<int>(9);
var child5 = new BinaryTree<int>(12);
var child6 = new BinaryTree<int>(13);
child1.Add(child4);
child1.Add(child5);
child2.Add(child6);
ITree<int> tree = rootBinaryTree;
Assert.AreEqual(tree.FindNode(target => target == 2), child1);
Assert.AreEqual(tree.FindNode(target => target == 9), child4);
Assert.AreEqual(tree.FindNode(target => target == 13), child6
);
Assert.AreEqual(tree.FindNode(target => target == 57), null);
}
示例3: Simple
public void Simple()
{
var binaryTree = new BinaryTree<int>(5);
Assert.AreEqual(binaryTree.Count, 0);
Assert.AreEqual(binaryTree.Degree, 0);
Assert.AreEqual(binaryTree.Data, 5);
binaryTree.Add(3);
Assert.AreEqual(binaryTree.Count, 1);
Assert.AreEqual(binaryTree.Degree, 1);
Assert.AreEqual(binaryTree.Data, 5);
Assert.AreEqual(binaryTree.Left.Data, 3);
Assert.IsNull(binaryTree.Right);
binaryTree.Add(4);
Assert.AreEqual(binaryTree.Count, 2);
Assert.AreEqual(binaryTree.Degree, 2);
Assert.AreEqual(binaryTree.Data, 5);
Assert.AreEqual(binaryTree.Left.Data, 3);
Assert.AreEqual(binaryTree.Right.Data, 4);
}
示例4: BeginTestMethod
public void BeginTestMethod()
{
target = new BinaryTree<String>();
target.Add(3, "three");
target.Add(2, "two");
target.Add(7, "seven");
}
示例5: Simple
public void Simple()
{
var binaryTree = new BinaryTree<int>(5);
var child1 = new BinaryTree<int>(2);
var child2 = new BinaryTree<int>(3);
binaryTree.Add(child1);
binaryTree.Add(child2);
var child4 = new BinaryTree<int>(9);
var child5 = new BinaryTree<int>(12);
var child6 = new BinaryTree<int>(13);
child1.Add(child4);
child1.Add(child5);
child2.Add(child6);
Assert.AreEqual(binaryTree.FindNode(target => target == 2), child1);
Assert.AreEqual(binaryTree.FindNode(target => target == 9), child4);
Assert.AreEqual(binaryTree.FindNode(target => target == 13), child6);
Assert.AreEqual(binaryTree.FindNode(target => target == 57), null);
}
示例6: DuplicateKeysNotAllowed
public void DuplicateKeysNotAllowed()
{
BinaryTree<int, string> tree = new BinaryTree<int, string>();
tree.Add(3, "a");
tree.Add(3, "a");
}
示例7: Add_ToFullIntTree_ExpandsTree
public void Add_ToFullIntTree_ExpandsTree()
{
BinaryTree<int> tree = new BinaryTree<int>(new int[] { 54, 25, 316, 4, 55, 6, });
tree.Add(11);
tree.Add(41);
tree.Add(111);
Assert.AreEqual(9, tree.Count);
}
示例8: IndexTest
public void IndexTest()
{
var d = new BinaryTree<int, bool>();
d.Add(10, true);
d.Add(20, true);
d.Add(30, true);
d.Add(40, true);
d.Add(25, true);
Assert.AreEqual(2, d.IndexOfKey(25));
}
示例9: CountTest
public void CountTest()
{
var tree = new BinaryTree<int>();
tree.Add(new BinaryTreeNode<int>(1));
Assert.AreEqual(1, tree.Count);
tree.Add(new BinaryTreeNode<int>(2));
Assert.AreEqual(2, tree.Count);
tree.Add(new BinaryTreeNode<int>(0));
Assert.AreEqual(3, tree.Count);
}
示例10: BinaryTreeAddLeaf
public void BinaryTreeAddLeaf()
{
var tree = new BinaryTree<int>();
tree.Add(4);
tree.Add(1);
tree.Add(10);
tree.ShouldContain(1);
tree.ShouldContain(4);
tree.ShouldContain(10);
}
示例11: Creation
public void Creation()
{
BinaryTree<int> Tree = new BinaryTree<int>();
Tree.Add(1);
Tree.Add(2);
Tree.Add(0);
Tree.Add(-1);
Assert.Equal(-1, Tree.MinValue);
Assert.Equal(2, Tree.MaxValue);
}
示例12: BinaryTree_Test
public void BinaryTree_Test()
{
BinaryTree<int> tree = new BinaryTree<int>();
tree.Add(5);
tree.Add(10);
tree.Add(80);
tree.Add(5);
tree.Add(2);
Assert.AreEqual(4, tree.Count);
}
示例13: Main
/// <summary>
/// Main program method
/// </summary>
/// <param name="args"></param>
private static void Main(string[] args)
{
var tree = new BinaryTree<int>();
tree.Add(5);
tree.Add(3);
tree.Add(6);
tree.Print();
tree.Delete(6);
tree.Print();
Console.WriteLine(tree.Contains(6));
}
示例14: DeleteTest2
public void DeleteTest2()
{
var tree = new BinaryTree<int>();
tree.Add(4);
tree.Add(1);
tree.Add(3);
tree.Add(2);
tree.Add(5);
tree.Delete(4);
Assert.IsTrue(tree.Contains(3));
}
示例15: BinaryTreeTest_Add
public void BinaryTreeTest_Add()
{
BinaryTree<int> tree = new BinaryTree<int>();
tree.Add(6);
tree.Add(3);
tree.Add(9);
tree.Add(1);
tree.Add(4);
int i = 0;
}