当前位置: 首页>>代码示例>>C#>>正文


C# Tree.ToString方法代码示例

本文整理汇总了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");
        }
开发者ID:Joxx0r,项目名称:ATF,代码行数:57,代码来源:TestTree.cs

示例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);
 }
开发者ID:gartdan,项目名称:vs2015demos,代码行数:7,代码来源:TreeTests.cs

示例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);
 }
开发者ID:gblosser,项目名称:OpenNlp,代码行数:13,代码来源:AuxiliaryTree.cs

示例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;
 }
开发者ID:gblosser,项目名称:OpenNlp,代码行数:37,代码来源:AuxiliaryTree.cs


注:本文中的Tree.ToString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。