Exemple #1
0
        public void Add(T item)
        {
            BinFa <T> addFa = this;
            BinFa <T> newFa = new BinFa <T>(item);
            int       ii    = item.CompareTo(addFa.Root.Core);

            //other = addFa;

            Console.WriteLine(addFa.Root.Core);

            if (ii < 0)
            {
                if (addFa.Next(false) == null)
                {
                    newFa.Insert(false, item);
                    addFa.Add(item);
                }
                else
                {
                    addFa = addFa.Next(false);
                }
            }
            else if (ii > 0)
            {
                if (addFa.Next(true) == null)
                {
                    newFa.Insert(true, item);
                    addFa.Add(item);
                }
                else
                {
                    addFa = addFa.Next(false);
                }
            }
        }
Exemple #2
0
        public void Add2(T item)
        {
            BinFa <T> insertFa = this;
            Node <T>  p        = new Node <T>(item);
            int       ii       = item.CompareTo(insertFa.Root.Core);

            if (ii < 0)
            {
                RootRight(p);
            }
            else
            {
                RootLeft(p);
            }
        }
Exemple #3
0
        public BinFa <T> Next(bool isRight)
        {
            BinFa <T> fa;

            if (isRight)
            {
                fa = new BinFa <T>(Root.Right);
            }
            else
            {
                fa = new BinFa <T>(Root.Left);
            }

            return(fa);
        }
Exemple #4
0
        static void Main(string[] args)
        {
            string         item  = "kutya";
            BinFa <string> binFa = new BinFa <string>(item);

            //binFa.Insert(true, "almafa");
            //binFa.Insert(false, "körtefa");
            //binFa.Insert(false, "diofa");
            //binFa.Insert(true, "szilvafa");
            //binFa.Insert(false, "fügefa");
            binFa.Add2("almafa");
            binFa.Add2("körtefa");
            binFa.Add2("diofa");
            binFa.Add2("szilvafa");
            binFa.Add2("fügefa");
            binFa.Add2("meggyfa");
            binFa.Print();
            Console.ReadKey();
        }
Exemple #5
0
        public void Print()
        {
            BinFa <T> printFa = this;
            BinFa <T> otherFa;

            if (printFa == null)
            {
                return;
            }

            Console.WriteLine(Root.Core);
            otherFa = printFa;
            if (printFa.Root.Left != null)
            {
                printFa = printFa.Next(false);
                printFa.Print();
            }
            printFa = otherFa;
            if (printFa.Root.Right != null)
            {
                printFa = printFa.Next(true);
                printFa.Print();
            }
        }