Esempio n. 1
0
        public void Insert(string v)
        {
            if (Root == null)
            {
                Root = new NodoBusqueda(v);
                return;
            }
            NodoBusqueda actual = Root;
            NodoBusqueda father = null;

            while (actual != null)
            {
                if (actual.keys.Count == 5)
                {
                    if (father == null)
                    {
                        string         x        = actual.Pop(1);
                        NodoBusqueda   NewRoot  = new NodoBusqueda(x);
                        NodoBusqueda[] newNodos = actual.Split();
                        NewRoot.InsertEdge(newNodos[0]);
                        NewRoot.InsertEdge(newNodos[1]);
                        NewRoot.InsertEdge(newNodos[2]);
                        NewRoot.InsertEdge(newNodos[3]);
                        Root   = NewRoot;
                        actual = NewRoot;
                    }
                    else
                    {
                        string x = actual.Pop(1);
                        if (x != null)
                        {
                            father.Push(x);
                        }
                        NodoBusqueda[] nNodos = actual.Split();
                        int            pos1   = father.FindEdgePosition(nNodos[1].keys[0]);
                        father.InsertEdge(nNodos[1]);

                        int Actualpos = father.FindEdgePosition(v);
                        actual = father.GetEdge(Actualpos);
                    }
                }
                father = actual;
                actual = actual.Traverse(v);
                if (actual == null)
                {
                    father.Push(v);
                }
            }
        }
Esempio n. 2
0
        public NodoBusqueda Find(string x)
        {
            NodoBusqueda c = Root;

            while (c != null)
            {
                if (c.Key(x) >= 0)
                {
                    return(x);
                }
                else
                {
                    int p = c.FindEdgePosition(x);
                    c = c.GetEdge(p);
                }
            }
            return(null);
        }