本文整理汇总了C#中Tree.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# Tree.ToString方法的具体用法?C# Tree.ToString怎么用?C# Tree.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tree
的用法示例。
在下文中一共展示了Tree.ToString方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestEverything
public void TestEverything()
{
Tree<string> test = new Tree<string>("a");
Assert.True(test.IsLeaf);
Assert.True(test.Parent == null);
Assert.True(test.DescendantCount == 1);
Assert.True(test.Level == 0);
Assert.True(test.IsDescendantOf(test));
Tree<string> b = new Tree<string>("b");
test.Children.Add(b);
Assert.True(b.Parent == test);
Tree<string> c = new Tree<string>("c");
test.Children.Add(c);
Assert.True(test.ToString() == "(a(b,c))");
test.Children.Insert(1, new Tree<string>("x"));
Assert.True(test.ToString() == "(a(b,x,c))");
test.Children.RemoveAt(1);
Assert.True(test.ToString() == "(a(b,c))");
Tree<string> subtree = new Tree<string>("d");
subtree.Children.Add(new Tree<string>("e"));
subtree.Children.Add(new Tree<string>("f"));
test.Children.Insert(1, subtree);
Assert.True(test.ToString() == "(a(b,d(e,f),c))");
Assert.True(test.DescendantCount == 6);
Assert.True(subtree.IsDescendantOf(test));
string s;
s = "";
foreach (Tree<string> t in test.Children)
s += t.Value.ToString();
Assert.True(s == "bdc");
s = "";
foreach (Tree<string> t in test.PreOrder)
s += t.Value.ToString();
Assert.True(s == "abdefc");
s = "";
foreach (Tree<string> t in test.PostOrder)
s += t.Value.ToString();
Assert.True(s == "befdca");
s = "";
foreach (Tree<string> t in test.LevelOrder)
s += t.Value.ToString();
Assert.True(s == "abdcef");
}
示例2: ToString_ReturnsBFSString
public void ToString_ReturnsBFSString()
{
var tree = new Tree<int>();
tree.Add(3).Add(2).Add(5).Add(4);
var result = tree.ToString();
Assert.AreEqual("3 2 5 4 ", result);
}
示例3: AuxiliaryTree
public AuxiliaryTree(Tree tree, bool mustHaveFoot)
{
originalTreeString = tree.ToString();
this.Tree = tree;
this.Foot = FindFootNode(tree);
if (Foot == null && mustHaveFoot)
{
throw new TsurgeonParseException("Error -- no foot node found for " + originalTreeString);
}
pnamesToNodes = new Dictionary<string, Tree>();
nodesToNames = new IdentityDictionary<Tree, string>();
InitializeNamesNodesMaps(tree);
}
示例4: FindFootNodeHelper
private static Tree FindFootNodeHelper(Tree t)
{
Tree foundDtr = null;
if (t.IsLeaf())
{
var match = FootNodeLabelPattern.Match(t.Label().Value());
if (match.Success)
{
t.Label().SetValue(match.Groups[1].Value);
return t;
}
else
{
return null;
}
}
foreach (Tree child in t.Children())
{
Tree thisFoundDtr = FindFootNodeHelper(child);
if (thisFoundDtr != null)
{
if (foundDtr != null)
{
throw new TsurgeonParseException("Error -- two foot nodes in subtree" + t.ToString());
}
else
{
foundDtr = thisFoundDtr;
}
}
}
/*Matcher m = escapedFootNodeCharacter.matcher(t.label().value());
t.label().setValue(m.replaceAll(footNodeCharacter));*/
var newS = EscapedFootNodeCharacter.Replace(t.Label().Value(), FootNodeCharacter);
t.Label().SetValue(newS);
return foundDtr;
}