예제 #1
0
        private void RecursiveAddLeaf(LeafWord data, Leaf <LeafWord> leaf)
        {
            if (leaf == null)
            {
                return;
            }
            if (leaf.Data.Word == data.Word)
            {
                leaf.Data.Lines.Add(data.Lines[0]);
            }

            if (data.Word.CompareTo(leaf.Data.Word) < 0)
            {
                if (leaf.Left == null)
                {
                    leaf.Left = new Leaf <LeafWord>(data);
                }
                else
                {
                    RecursiveAddLeaf(data, leaf.Left);
                }
            }

            else if (data.Word.CompareTo(leaf.Data.Word) > 0)
            {
                if (leaf.Right == null)
                {
                    leaf.Right = new Leaf <LeafWord>(data);
                }
                else
                {
                    RecursiveAddLeaf(data, leaf.Right);
                }
            }
        }
예제 #2
0
 public override void AddLeaf(LeafWord data)
 {
     if (RootLeaf == null)
     {
         RootLeaf = new Leaf <LeafWord>(data);
         RootData = RootLeaf.Data;
     }
     else
     {
         RecursiveAddLeaf(data, RootLeaf);
     }
     Count++;
 }