Example #1
0
    public void PlayWithTree()
    {
        NTree <int> tree = new NTree <int>();

        //  Initialize tree
        //  If the tree has 47 nodes, WreakHavoc will be called 47 times,
        //  once for each node in the tree.
        tree.traverse(WreakHavoc);
    }
Example #2
0
        public override List <PostInfo> WatchAllComments(UserInfo u, PostInfo s)
        {
            NTree <PostInfo> node   = null;
            List <PostInfo>  result = new List <PostInfo>();

            tree.traverse(delegate(NTree <PostInfo> curnode)
            {
                if (curnode.getData() != null && curnode.getData().id == s.id)
                {
                    node = curnode;
                }
            });
            if (node == null)
            {
                return(null);
            }
            for (int i = 0; i < node.childsCount(); i++)
            {
                result.Add(node.getChild(i).getData());
            }
            return(result);
        }
        private List <IWizardBaseController> SortComponents(List <IWizardBaseController> unsorted)
        {
            List <IWizardBaseController> components = new List <IWizardBaseController>();
            Dictionary <string, NTree <IWizardBaseController> > nodes = new Dictionary <string, NTree <IWizardBaseController> >();
            NTree <IWizardBaseController> rootNode = null;

            //build the tree
            foreach (IWizardBaseController component in unsorted)
            {
                NTree <IWizardBaseController> node = null;
                if (!nodes.ContainsKey(component.ControllerName))
                {
                    node = new NTree <IWizardBaseController>(component);
                    nodes.Add(component.ControllerName, node);
                }
                else
                {
                    node = nodes[component.ControllerName];
                }

                //check for null prereq before we contine.  Null prereq denotes root node
                if (component.Prerequisite != null)
                {
                    NTree <IWizardBaseController> parentNode = null;
                    if (nodes.ContainsKey(component.Prerequisite.ControllerName))
                    {
                        parentNode = nodes[component.Prerequisite.ControllerName];
                    }
                    else
                    {
                        parentNode = new NTree <IWizardBaseController>(component.Prerequisite as IWizardBaseController);
                        nodes.Add(component.Prerequisite.ControllerName, parentNode);
                    }
                    parentNode.addChild(node);
                }
                else
                {
                    //set root node for later traversal
                    rootNode = node;
                }
            }

            //traverse tree, add to the list of components
            rootNode.traverse(rootNode, (data) => { components.Add(data); });
            return(components);
        }