本文整理汇总了C#中GeneralTree.GetChild方法的典型用法代码示例。如果您正苦于以下问题:C# GeneralTree.GetChild方法的具体用法?C# GeneralTree.GetChild怎么用?C# GeneralTree.GetChild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GeneralTree
的用法示例。
在下文中一共展示了GeneralTree.GetChild方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Get
public void Get()
{
var root = new GeneralTree<int>(5) { 2, 3 };
root.GetChild(0).Parent = root.GetChild(1);
Assert.AreSame(((ITree<int>)root.GetChild(0)).Parent, root);
}
示例2: Simple
public void Simple()
{
var root = new GeneralTree<int>(5);
var child1 = new GeneralTree<int>(2);
var child2 = new GeneralTree<int>(3);
var child3 = new GeneralTree<int>(5);
var child4 = new GeneralTree<int>(7);
root.Add(child1);
root.Add(child2);
Assert.AreEqual(root.Count, 2);
Assert.AreEqual(root.Degree, 2);
root.RemoveAt(0);
Assert.IsNull(child1.Parent);
Assert.AreEqual(root.Count, 1);
Assert.AreEqual(root.Degree, 1);
Assert.AreEqual(root.GetChild(0), child2);
Assert.AreEqual(root.GetChild(0).Data, 3);
root.Add(child1);
Assert.AreEqual(child1.Parent, root);
Assert.AreEqual(root.Count, 2);
Assert.AreEqual(root.Degree, 2);
Assert.IsTrue(root.Remove(child1));
Assert.IsNull(child1.Parent);
Assert.AreEqual(root.Count, 1);
Assert.AreEqual(root.Degree, 1);
Assert.AreEqual(root.GetChild(0), child2);
Assert.AreEqual(root.GetChild(0).Data, 3);
Assert.IsFalse(root.Remove(child3));
root.Add(child3);
root.Add(child4);
Assert.AreEqual(root.Count, 3);
Assert.AreEqual(root.Degree, 3);
var fiveNode = root.FindNode(target => target == 5);
Assert.IsTrue(root.Remove(5));
Assert.IsNull(fiveNode.Parent);
Assert.AreEqual(root.Count, 2);
Assert.AreEqual(root.Degree, 2);
Assert.AreEqual(root.GetChild(1).Data, 7);
Assert.IsFalse(root.Remove(13));
}
示例3: ExceptionInvalidSubTreeNegative
public void ExceptionInvalidSubTreeNegative()
{
var root = new GeneralTree<int>(5);
var child1 = new GeneralTree<int>(2);
root.Add(child1);
root.GetChild(-1);
}
示例4: Simple
public void Simple()
{
var root = new GeneralTree<int>(5);
var child1 = new GeneralTree<int>(2);
var child2 = new GeneralTree<int>(3);
root.Add(child1);
root.Add(child2);
Assert.AreEqual(child1.Parent, root);
Assert.AreEqual(child2.Parent, root);
Assert.AreEqual(root.Count, 2);
Assert.AreEqual(root.Degree, 2);
Assert.AreEqual(root.GetChild(0), child1);
Assert.AreEqual(root.GetChild(0).Data, child1.Data);
Assert.AreEqual(root.GetChild(1).Data, child2.Data);
Assert.AreEqual(root.GetChild(1), child2);
root = new GeneralTree<int>(5)
{
2,
3
};
Assert.AreEqual(root.GetChild(0).Data, child1.Data);
Assert.AreEqual(root.GetChild(1).Data, child2.Data);
Assert.AreEqual(root.GetChild(0).Parent, root);
Assert.AreEqual(root.GetChild(1).Parent, root);
var anotherRoot = new GeneralTree<int>(2);
var movedChild = root.GetChild(0);
anotherRoot.Add(movedChild);
Assert.AreEqual(movedChild.Parent, anotherRoot);
Assert.AreEqual(root.Degree, 1);
Assert.AreEqual(root.GetChild(0).Parent, root);
}
示例5: Interface
public void Interface()
{
var root = new GeneralTree<int>(5);
var child1 = new GeneralTree<int>(2);
var child2 = new GeneralTree<int>(3);
((ITree<int>)root).Add(child1);
((ITree<int>)root).Add(child2);
Assert.AreEqual(root.Count, 2);
Assert.AreEqual(root.Degree, 2);
Assert.AreEqual(root.GetChild(0), child1);
Assert.AreEqual(root.GetChild(0).Data, child1.Data);
Assert.AreEqual(root.GetChild(1).Data, child2.Data);
Assert.AreEqual(root.GetChild(1), child2);
}
示例6: Set
public void Set()
{
var root = new GeneralTree<int>(5) { 2, 3 };
Assert.AreEqual(root.GetChild(0).Data, 2);
Assert.AreEqual(root.GetChild(1).Data, 3);
Assert.AreEqual(root.GetChild(0).Parent, root);
Assert.AreEqual(root.GetChild(1).Parent, root);
root.GetChild(0).Parent = root.GetChild(1);
Assert.AreEqual(root.ChildNodes.Count, 1);
Assert.AreEqual(root.GetChild(0).ChildNodes.Count, 1);
Assert.AreEqual(root.GetChild(0).GetChild(0).Data, 2);
Assert.AreEqual(root.GetChild(0).Data, 3);
Assert.AreSame(root.GetChild(0).GetChild(0).Parent, root.GetChild(0));
Assert.AreSame(root.GetChild(0).Parent, root);
}