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


C# TreeNode.Add方法代码示例

本文整理汇总了C#中TreeNode.Add方法的典型用法代码示例。如果您正苦于以下问题:C# TreeNode.Add方法的具体用法?C# TreeNode.Add怎么用?C# TreeNode.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TreeNode的用法示例。


在下文中一共展示了TreeNode.Add方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

        private static void Main(string[] args)
        {
            var file = new TreeNode(1, "File");
            file.Add(new TreeNode(2, "Save"));
            file.Add(new TreeNode(3, "End"));
            var edit = new TreeNode(4, "Edit") { new TreeNode(5, "Paste"), new TreeNode(6, "Copy") };
            file.Add(edit);

            Output(file);
            Output(edit);

            Console.ReadKey();
        }
开发者ID:zarmsen,项目名称:pattern,代码行数:13,代码来源:Program.cs

示例2: BuildTreeFromUserInput

        public static TreeNode<int> BuildTreeFromUserInput()
        {
            Console.Write("Please enter nodes number N: ");
            var nodesNumber = int.Parse(Console.ReadLine());

            var nodes = new List<TreeNode<int>>();

            for (int i = 0; i < nodesNumber - 1; i++)
            {
                var pair = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                var parentValue = int.Parse(pair[0]);
                var childValue = int.Parse(pair[1]);

                if (nodes.Any(n => n.Value == parentValue) && nodes.Any(n => n.Value == childValue))
                {
                    var parent = nodes.Find(p => p.Value == parentValue);
                    var child = nodes.Find(c => c.Value == childValue);

                    parent.Add(child);
                    child.Parent = parent;
                }
                else if (nodes.Any(n => n.Value == parentValue))
                {
                    var parent = nodes.Find(p => p.Value == parentValue);
                    var child = new TreeNode<int>(childValue);

                    parent.Add(child);
                    child.Parent = parent;
                    nodes.Add(child);
                }
                else if (nodes.Any(n => n.Value == childValue))
                {
                    var parent = new TreeNode<int>(parentValue);
                    var child = nodes.Find(p => p.Value == childValue);

                    parent.Add(child);
                    child.Parent = parent;
                    nodes.Add(parent);
                }
                else
                {
                    var parent = new TreeNode<int>(parentValue);
                    var child = new TreeNode<int>(childValue);

                    parent.Add(child);
                    child.Parent = parent;

                    nodes.Add(parent);
                    nodes.Add(child);
                }
            }

            return nodes.FirstOrDefault(n => n.IsRoot);
        }
开发者ID:p0150n,项目名称:TelerikAcademy,代码行数:54,代码来源:Startup.cs

示例3: ParseTreeBracketsComma

 public static TreeNode<string> ParseTreeBracketsComma(this string toParse)
 {
     //Console.WriteLine("parsing {0}");
     int funcsep = toParse.IndexOf('(');
     if(funcsep < 0x00) {
         funcsep = toParse.Length;
     }
     int b = 0x00;
     int last = funcsep+0x01;
     char c;
     TreeNode<string> result = new TreeNode<string>(toParse.Substring(0x00, funcsep));
     for(int i = funcsep+0x01; i < toParse.Length; i++) {
         c = toParse[i];
         if(c == '(') {
             b++;
         }
         else if(c == ')') {
             b--;
             if(b < 0x00) {
                 result.Add(ParseTreeBracketsComma(toParse.Substring(last, i-last)));
                 return result;
             }
         }
         else if(c == ',') {
             if(b <= 0x00) {
                 result.Add(ParseTreeBracketsComma(toParse.Substring(last, i-last)));
                 last = i+0x01;
             }
         }
     }
     return result;
 }
开发者ID:KommuSoft,项目名称:MoRen,代码行数:32,代码来源:ParserUtils.cs

示例4: RearrangeNodes

    private void RearrangeNodes(ref TreeNode node)
    {
        TreeNode BrokenNode = node.LeftNode;
        if (node.RightNode != null)
        {
            node = node.RightNode;

            if (BrokenNode != null)
            {
                foreach (int number in BrokenNode)
                {
                    node.Add(number);
                }
            }
        }
        else
        {
            node = BrokenNode;
        }
    }
开发者ID:shnogeorgiev,项目名称:Software-University-Courses,代码行数:20,代码来源:TreeNode.cs

示例5: __Application

        public void __Application(IApplicationLoader app)
        {
            //app.LoadingAnimation.FadeOut();

            var DefaultTitle = "jsc solutions";


            Native.Document.title = DefaultTitle;

            StringActionAction GetTitleFromServer = new UltraWebService().GetTitleFromServer;



            GetTitleFromServer(
                n => Native.Document.title = n
            );

            var MyPagesBackground = new IHTMLDiv
            {

            };

            MyPagesBackground.style.overflow = IStyle.OverflowEnum.hidden;
            MyPagesBackground.style.position = IStyle.PositionEnum.absolute;
            MyPagesBackground.style.width = "100%";
            MyPagesBackground.style.height = "100%";
            MyPagesBackground.AttachToDocument();

            var MyPages = new IHTMLDiv
            {

            };

            MyPages.style.overflow = IStyle.OverflowEnum.auto;
            MyPages.style.position = IStyle.PositionEnum.absolute;
            MyPages.style.width = "100%";
            MyPages.style.height = "100%";
            MyPages.AttachToDocument();

            var MyPagesInternal = new IHTMLDiv();

            MyPagesInternal.style.margin = "4em";
            MyPagesInternal.AttachTo(MyPages);

            // http://www.google.com/support/forum/p/Google+Analytics/thread?tid=486a963e463df665&hl=en
            var gapathname = Native.Document.location.pathname;
            var gasearch = Native.Document.location.search;
            var gahash = Native.Window.escape(Native.Document.location.hash);
            var gapageview = gapathname + gasearch + gahash;

            var hash = Native.Document.location.hash;

            Action<string> Analytics = delegate { };

        #region logo
            {
                var IsStudio = Native.Document.location.hash.StartsWith("#/studio");

                if (Native.Document.location.host.StartsWith("studio."))
                {
                    IsStudio = true;
                }

                if (IsStudio)
                {
                    new StudioView(AddSaveButton).Content.AttachToDocument();
                }
                else if (Native.Document.location.hash.StartsWith("#/docs"))
                {
                    var view = new DocumentationCompilationViewer();

                    view.TouchTypeSelected +=
                        type =>
                        {
                            Native.Document.location.hash = "#/docs/" + type.FullName;

                            Analytics("#/docs/" + type.FullName);
                        };

                }
                else if (Native.Document.location.hash.StartsWith("#/warehouse"))
                {
                    new UltraWebService().ThreeDWarehouse(
                        y =>
                        {
                            Func<string, IHTMLAnchor> Build =
                                mid =>
                                {
                                    var a = new IHTMLAnchor { href = "http://sketchup.google.com/3dwarehouse/details?ct=hppm&mid=" + mid }.AttachTo(MyPagesInternal);
                                    var img = new IHTMLImage { src = "http://sketchup.google.com/3dwarehouse/download?rtyp=st&ctyp=other&mid=" + mid }.AttachTo(a);

                                    return a;
                                };

                            var imgs = Enumerable.ToArray(
                                from k in y.Elements()
                                select Build(k.Value)

                            );
                        }
//.........这里部分代码省略.........
开发者ID:exaphaser,项目名称:JSC-Cross-Compiler,代码行数:101,代码来源:Application.cs

示例6: GetFXReadAddrList

        private static TreeNode<string, FXRegisterReadAddrItem> GetFXReadAddrList(XmlNode attributeNode, Dictionary<string, FXRegister> registerDict)
        {
            TreeNode<string, FXRegisterReadAddrItem> rootNode = new TreeNode<string, FXRegisterReadAddrItem>();
            XmlNodeList registerNodeList = attributeNode.SelectSingleNode("RegisterReadAddrList").ChildNodes;
            foreach (XmlNode registerNode in registerNodeList)              //第一层循环,解出寄存器类型,这一层只有寄存器名称
            {
                if(registerNode.NodeType == XmlNodeType.Element)
                {
                    FXRegisterReadAddrItem item1Level = new FXRegisterReadAddrItem();
                    item1Level.Register = registerNode.Attributes["name"].Value;
                    TreeNode<string, FXRegisterReadAddrItem> item1LevelNode = new TreeNode<string, FXRegisterReadAddrItem>();
                    item1LevelNode.Key = item1Level.Register;
                    rootNode.Add(item1LevelNode.Key, item1LevelNode);                   //添加树的第一层子节点
                    if (registerDict.ContainsKey(item1LevelNode.Key))              //有这个寄存器类型才添加
                    {
                        FXRegister register = registerDict[item1LevelNode.Key];
                        XmlNodeList readAddrNodeList = registerNode.ChildNodes;
                        foreach (XmlNode readAddrNode in readAddrNodeList)      //第二层循环,解出FXRegisterReadAddrType列出的所有类型地址
                        {
                            if (readAddrNode.NodeType == XmlNodeType.Element)
                            {
                                FXRegisterReadAddrItem item2Level = new FXRegisterReadAddrItem();
                                item2Level.Register = item1LevelNode.Key;
                                item2Level.IsOutputItem = false;
                                item2Level.NameFormatType = register.NameFormatType;
                                item2Level.Type = Convert.ToInt32(readAddrNode.Attributes["type"].Value);
                                if (readAddrNode.Attributes["bitmask"] != null)
                                    item2Level.Bitmask = Convert.ToInt32(readAddrNode.Attributes["bitmask"].Value);
                                if (readAddrNode.Attributes["from"] != null)
                                    item2Level.From = Convert.ToInt32(readAddrNode.Attributes["from"].Value);
                                TreeNode<string, FXRegisterReadAddrItem> item2LevelNode = new TreeNode<string, FXRegisterReadAddrItem>();
                                item2LevelNode.Key = item2Level.Type.ToString();
                                item2LevelNode.Value = item2Level;
                                item1LevelNode.Add(item2LevelNode.Key, item2LevelNode);             //添加树的第二层子节点

                                XmlNodeList readAddrOutputNodeList = readAddrNode.ChildNodes;
                                if (readAddrOutputNodeList != null&&readAddrOutputNodeList.Count>0)             //如果是output类型的节点,那么执行第三层循环
                                {
                                    foreach (XmlNode readAddrOutputNode in readAddrOutputNodeList)      //第三层循环,解出FXRegisterReadAddrOutputType列出的所有输出类型地址
                                    {
                                        if (readAddrOutputNode.NodeType == XmlNodeType.Element)
                                        {
                                            FXRegisterReadAddrItem item3Level = new FXRegisterReadAddrItem();
                                            item3Level.Register = item1LevelNode.Key;
                                            item3Level.IsOutputItem = true;
                                            item3Level.NameFormatType = register.NameFormatType;
                                            item3Level.Type = Convert.ToInt32(readAddrOutputNode.Attributes["type"].Value);
                                            item3Level.From = Convert.ToInt32(readAddrOutputNode.Attributes["from"].Value);
                                            item3Level.Bitmask = Convert.ToInt32(readAddrOutputNode.Attributes["bitmask"].Value);
                                            TreeNode<string, FXRegisterReadAddrItem> item3LevelNode = new TreeNode<string, FXRegisterReadAddrItem>();
                                            item3LevelNode.Key = item3Level.Type.ToString();
                                            item3LevelNode.Value = item3Level;
                                            item2LevelNode.Add(item3LevelNode.Key, item3LevelNode);             //添加树的第三层子节点
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return rootNode;
        }
开发者ID:cubean,项目名称:CG,代码行数:63,代码来源:FXConfigReader.cs

示例7: TestRemoveExistingNodeThatIsRoot

        public void TestRemoveExistingNodeThatIsRoot()
        {
            var root = new TreeNode<int>(1);
            root.Add(2);
            root.Add(3);
            root.Add(4);
            root.Children.ElementAt(0).Add(5);
            root.Children.ElementAt(1).Add(6);
            root.Children.ElementAt(2).Add(7);
            bool removeResult = root.Remove(1);

            // the removal of the root element is not allowed
            Assert.IsFalse(removeResult);
        }
开发者ID:gentian-kasa,项目名称:Wall-AI,代码行数:14,代码来源:TreeNodeTest.cs

示例8: TestRemoveExistingNodeThatIsNotRoot

        public void TestRemoveExistingNodeThatIsNotRoot()
        {
            var root = new TreeNode<int>(1);
            root.Add(2);
            root.Add(3);
            root.Add(4);
            root.Children.ElementAt(0).Add(5);
            root.Children.ElementAt(1).Add(6);
            root.Children.ElementAt(2).Add(7);
            bool removalResult = root.Remove(6);
            int[] expected = { 1, 2, 3, 4, 5, 7 };
            var bfEnumerator = root.GetEnumerator(VisitType.BreadthFirst);
            var elements = new List<int>();

            while (bfEnumerator.MoveNext())
            {
                elements.Add(bfEnumerator.Current);
            }

            var actual = elements.ToArray();

            Assert.IsTrue(removalResult);
            Assert.AreEqual(expected.Length, actual.Length);
            Assert.AreEqual(expected.Length, root.Count);

            for (int i = 0; i < expected.Length; i++)
            {
                Assert.AreEqual(expected[i], actual[i]);
            }
        }
开发者ID:gentian-kasa,项目名称:Wall-AI,代码行数:30,代码来源:TreeNodeTest.cs

示例9: TestFindNotExistingElementWithIterativeDeepening

        public void TestFindNotExistingElementWithIterativeDeepening()
        {
            var root = new TreeNode<int>(1);
            root.Add(2);
            root.Add(3);
            root.Add(4);
            root.Children.ElementAt(0).Add(5);
            root.Children.ElementAt(1).Add(6);
            root.Children.ElementAt(2).Add(7);
            var actual = root.Contains(8, SearchMode.IterativeDeepening);

            Assert.IsFalse(actual);
        }
开发者ID:gentian-kasa,项目名称:Wall-AI,代码行数:13,代码来源:TreeNodeTest.cs

示例10: TestFindNotExistingElementWithDFS

        public void TestFindNotExistingElementWithDFS()
        {
            var root = new TreeNode<int>(1);
            root.Add(2);
            root.Add(3);
            root.Add(4);
            root.Children.ElementAt(0).Add(5);
            root.Children.ElementAt(1).Add(6);
            root.Children.ElementAt(2).Add(7);
            var actual = root.Contains(8, SearchMode.DepthFirstSearch);

            Assert.IsFalse(actual);
        }
开发者ID:gentian-kasa,项目名称:Wall-AI,代码行数:13,代码来源:TreeNodeTest.cs

示例11: TestFindExistingElementWithBFS

        public void TestFindExistingElementWithBFS()
        {
            var root = new TreeNode<int>(1);
            root.Add(2);
            root.Add(3);
            root.Add(4);
            root.Children.ElementAt(0).Add(5);
            root.Children.ElementAt(1).Add(6);
            root.Children.ElementAt(2).Add(7);
            var actual = root.Contains(7, SearchMode.BreadthFirstSearch);

            Assert.IsTrue(actual);
        }
开发者ID:gentian-kasa,项目名称:Wall-AI,代码行数:13,代码来源:TreeNodeTest.cs

示例12: TestTreeNodeElementAddition

        public void TestTreeNodeElementAddition()
        {
            var root = new TreeNode<int>(4);
            root.Add(5);
            root.Add(6);
            root.Children.ElementAt(0).Add(7);

            Assert.AreEqual(4, root.Count);
            Assert.AreEqual(2, root.Children.Count());
            Assert.AreEqual(root, root.Children.ElementAt(0).Parent);
            Assert.AreEqual(root, root.Children.ElementAt(1).Parent);
        }
开发者ID:gentian-kasa,项目名称:Wall-AI,代码行数:12,代码来源:TreeNodeTest.cs


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