本文整理汇总了C#中Tree.Remove方法的典型用法代码示例。如果您正苦于以下问题:C# Tree.Remove方法的具体用法?C# Tree.Remove怎么用?C# Tree.Remove使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tree
的用法示例。
在下文中一共展示了Tree.Remove方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main()
{
var tree = new Tree<int>();
tree.Add(13);
tree.Add(18);
tree.Add(5);
tree.Add(20);
tree.Add(15);
tree.Add(5);
tree.Add(9);
tree.Add(3);
tree.Add(17);
tree.Add(10);
foreach (var item in tree)
{
Console.WriteLine("{0}", item);
}
tree.Remove(13);
foreach (var item in tree)
{
Console.WriteLine("{0}", item);
}
}
示例2: Run
void Run()
{
Scanner input = new Scanner(Console.In);
int N = input.NextInt();
char[] op = new char[N];
int[] arg = new int[N];
List<int> keys = new List<int>();
for (int i = 0; i < N; i++) {
string s = input.Next();
op[i] = char.ToUpper(s[0]);
arg[i] = input.NextInt();
if (op[i] == 'P')
keys.Add(arg[i]);
if (op[i] != 'P' && op[i] != 'G')
throw new Exception();
}
Tree tree = new Tree(keys.ToArray());
for (int i = 0; i < N; i++) {
if (op[i] == 'P') {
tree.Add(arg[i]);
} else {
try {
tree.Remove(tree.Find(arg[i]));
} catch (Exception e) {}
}
}
int[] res = tree.ToArray();
foreach (int i in res)
Console.WriteLine(i);
if (res.Length == 0)
Console.WriteLine("empty");
}
示例3: op_Remove_Tree
public void op_Remove_Tree()
{
var expected = new Tree<int>();
var obj = new Tree<int>
{
expected
};
obj.Remove(expected);
Assert.Null(expected.Parent);
Assert.Empty(obj);
}