Esempio n. 1
0
        private Boolean add(String s, int index)
        {
            if (index == s.Length)
            {
                if (isWord)
                {
                    return(false);
                }
                isWord = true;
                return(true);
            }
            char c = s[index]; //char c=s.charAt(index);

            for (int i = 0; i < numChildren; i++)
            {
                if (child[i].ch == c)
                {
                    return(child[i].add(s, index + 1));
                }
            }
            // this code adds from the bottom to the top because the addChild method
            // checks for cyclic references.  This prevents quadratic runtime.
            int  ii = s.Length - 1;
            Tire t  = createNode(s[ii--]);

            t.isWord = true;
            while (ii >= index)
            {
                Tire n = createNode(s[ii--]);
                n.addChild(t);
                t = n;
            }
            addChild(t);
            return(true);
        }