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