Example #1
0
        // Non-Recursive Depth-First Search Impl.
        // If has child, get first child
        // Else - If has sibling, get sibling
        // Else - Go up
        //      If has sibling, get sibling
        //      Else - Go up
        private Component PrivNextStep(Component pNode, Component pParent, Component pSibling)
        {
            Component childOrSibling = ReturnChildOrSibling(pNode, pSibling);

            // If pNode has children, return first child
            // Else if pNode has siblings, return next sibling
            if (childOrSibling != null)
            {
                return(childOrSibling);
            }
            else
            {
                // Go up a level and search for sibling
                while (pParent != null)
                {
                    pNode = pParent;

                    // If parent has sibling, return sibling
                    if (pNode.GetNext() != null)
                    {
                        return((Component)pNode.GetNext());
                    }
                    else
                    {
                        // Else go up another level
                        pParent = GetParent(pNode);
                    }
                }
            }

            // Is iteration complete?
            if ((pNode.containerType != Component.Container.LEAF) && (pParent == null))
            {
                pNode        = null;
                this.bIsDone = true;
            }

            return(pNode);
        }
        public Component GetChild(int index)
        {
            Debug.Assert(index <= this.GetNumChildren(), "There is no child at the current index");

            Component pTmp  = this.GetFirstChild();
            Component pNode = null;

            for (int i = 0; i < (index + 1); i++)
            {
                pNode = pTmp;
                pTmp  = (Component)pTmp.GetNext();
            }
            Debug.Assert(pNode != null);
            return(pNode);
        }
Example #3
0
 static public Component GetSibling(Component pNode)
 {
     Debug.Assert(pNode != null);
     return((Component)pNode.GetNext());
 }