Beispiel #1
0
        // Showcases how we can make the tree autogenerate itself and how flexible the structure is in terms of adding elements.
        static string MakeRandomIntTree(int iDepth, int iMaxDepth, int iMaxDigits, int iMaxChildren, int iSpaces)
        {
            Random       rRand   = new Random();
            CIntTreeNode itnRoot = new CIntTreeNode(MakeNumber(rRand, iMaxDigits));

            MakeRandomChildren(rRand, itnRoot, iDepth, iMaxDepth, iMaxChildren, iMaxDigits);

            return(itnRoot.WriteTreeToString(iSpaces));
        }
Beispiel #2
0
        static void MakeRandomChildren(Random rRand, CIntTreeNode itnNode, int iDepth, int iMaxDepth, int iMaxChildren, int iMaxDigits)
        {
            if (iDepth > iMaxDepth)
            {
                return;
            }

            int iChildren = rRand.Next(0, iMaxChildren);

            for (int i = 0; i < iChildren; ++i)
            {
                CIntTreeNode itnChild = new CIntTreeNode(MakeNumber(rRand, iMaxDigits), itnNode, CTreeNode.ENodeCreate.ENODE_LAST_CHILD);

                MakeRandomChildren(rRand, itnChild, iDepth + 1, iMaxDepth, iMaxChildren, iMaxDigits);
            }

            return;
        }
Beispiel #3
0
 public CIntTreeNode(int iVal, CIntTreeNode pNode, ENodeCreate eFlag) : base(pNode, eFlag)
 {
     m_iVal = iVal;
 }