Click here to Skip to main content
Click here to Skip to main content
Articles » Languages » C# » Generics » Downloads
 
Add your own
alternative version

Simple Generic Tree

, 6 Sep 2012 CPOL
Simple Generic Tree in c#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NodeTree;

namespace TestConsole
{
    class Program
    {
        static void Main(string[] args)
        {
            SpecialTreeNode rootTreeNode = new SpecialTreeNode("Node1");
            var node2a = new SpecialTreeNode("Node 2a");
            var node2b = new SpecialTreeNode("Node 2b");
            var node2c = new SpecialTreeNode("Node 2c");

            node2a.IsSpecial = true;
            node2c.IsSpecial = true;

            rootTreeNode.AddChild(node2a);
            rootTreeNode.AddChild(node2b);
            rootTreeNode.AddChild(node2c);

            var node3ca = new SpecialTreeNode("Node 3ca");
            node2c.AddChild(node3ca);

            Console.WriteLine(string.Format("Root has {0} nodes", rootTreeNode.ChildNodes.Count));
            Console.WriteLine(string.Format("Root has {0} special nodes", rootTreeNode.GetSpecialNodes().Count));
            Console.WriteLine(string.Format("Root has {0} special leaf nodes", rootTreeNode.GetSpecialLeafNodes().Count));
            Console.WriteLine(string.Format("Root has {0} leaf nodes", rootTreeNode.GetLeafNodes().Count));

            Console.WriteLine("Press any key to end");
            Console.ReadKey();
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

alc_aardvark

United Kingdom United Kingdom
No Biography provided

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150129.1 | Last Updated 6 Sep 2012
Article Copyright 2012 by alc_aardvark
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid