Exemplo n.º 1
0
 void PreOrderInt(BTDugumu dugum)
 {
     if (dugum == null)
     {
         return;
     }
     Ziyaret(dugum);
     PreOrderInt(dugum.sol);
     PreOrderInt(dugum.sag);
 }
Exemplo n.º 2
0
 void PostOrderInt(BTDugumu dugum)
 {
     if (dugum == null)
     {
         return;
     }
     PostOrderInt(dugum.sol);
     PostOrderInt(dugum.sag);
     Ziyaret(dugum);
 }
Exemplo n.º 3
0
 void InOrderInt(BTDugumu dugum)
 {
     if (dugum == null)
     {
         return;
     }
     InOrderInt(dugum.sol);
     Ziyaret(dugum);
     InOrderInt(dugum.sag);
 }
Exemplo n.º 4
0
 private BTDugumu OtelAraInt(BTDugumu dugum, string OtelAdi)
 {
     if (dugum == null)
     {
         return(null);
     }
     else if (dugum.otel.adi == OtelAdi)
     {
         return(dugum);
     }
     else if (string.Compare(dugum.otel.adi, OtelAdi) == 1)
     {
         return(OtelAraInt(dugum.sol, OtelAdi));
     }
     else
     {
         return(OtelAraInt(dugum.sag, OtelAdi));
     }
 }
Exemplo n.º 5
0
        BTDugumu Successor(BTDugumu silinecekDugum)
        {
            BTDugumu successorParent = silinecekDugum;
            BTDugumu successor       = silinecekDugum;
            BTDugumu current         = silinecekDugum.sag;

            while (current != null)
            {
                successorParent = successor;
                successor       = current;
                current         = current.sol;
            }
            if (successor != silinecekDugum.sag)
            {
                successorParent.sol = successor.sag;
                successor.sag       = silinecekDugum.sag;
            }
            return(successor);
        }
Exemplo n.º 6
0
        public void Ekle(Otel eklenecekOtel)
        {
            BTDugumu tempParent = new BTDugumu();

            BTDugumu tempSearch = kok;

            while (tempSearch != null)
            {
                tempParent = tempSearch;

                if (eklenecekOtel.adi == tempSearch.otel.adi)
                {
                    return;
                }
                else if (string.Compare(eklenecekOtel.adi, tempSearch.otel.adi) == -1)
                {
                    tempSearch = tempSearch.sol;
                }
                else
                {
                    tempSearch = tempSearch.sag;
                }
            }
            BTDugumu eklenecek = new BTDugumu(eklenecekOtel);

            if (kok == null)
            {
                kok = eklenecek;
            }
            else if (string.Compare(eklenecekOtel.adi, tempParent.otel.adi) == -1)
            {
                tempParent.sol = eklenecek;
            }
            else
            {
                tempParent.sag = eklenecek;
            }
        }
Exemplo n.º 7
0
        private int DerinlikBulInt(BTDugumu dugum)
        {
            if (dugum == null)
            {
                return(0);
            }
            else
            {
                /* compute the depth of each subtree */
                int lDepth = DerinlikBulInt(dugum.sol);
                int rDepth = DerinlikBulInt(dugum.sag);

                /* use the larger one */
                if (lDepth > rDepth)
                {
                    return(lDepth + 1);
                }
                else
                {
                    return(rDepth + 1);
                }
            }
        }
Exemplo n.º 8
0
 public BTDugumu(Otel otel)
 {
     this.otel = otel;
     sol       = null;
     sag       = null;
 }
Exemplo n.º 9
0
 void Ziyaret(BTDugumu dugum)
 {
     dugumler.Add(dugum);
 }
Exemplo n.º 10
0
        public bool Sil(Otel otel)
        {
            BTDugumu current = kok;
            BTDugumu parent  = kok;
            bool     kucukMu = true;

            while (current.otel.adi != otel.adi)
            {
                parent = current;
                if (string.Compare(otel.adi, current.otel.adi) == -1)
                {
                    kucukMu = true;
                    current = current.sol;
                }
                else
                {
                    kucukMu = false;
                    current = current.sag;
                }
                if (current == null)
                {
                    return(false);
                }
            }

            if (current.sol == null && current.sag == null)
            {
                if (current == kok)
                {
                    kok = null;
                }
                else if (kucukMu)
                {
                    parent.sol = null;
                }
                else
                {
                    parent.sag = null;
                }
            }

            else if (current.sag == null)
            {
                if (current == kok)
                {
                    kok = current.sol;
                }
                else if (kucukMu)
                {
                    parent.sol = current.sol;
                }
                else
                {
                    parent.sag = current.sol;
                }
            }
            else if (current.sol == null)
            {
                if (current == kok)
                {
                    kok = current.sag;
                }
                else if (kucukMu)
                {
                    parent.sol = current.sag;
                }
                else
                {
                    parent.sag = current.sag;
                }
            }

            else
            {
                BTDugumu successor = Successor(current);
                if (current == kok)
                {
                    kok = successor;
                }
                else if (kucukMu)
                {
                    parent.sol = successor;
                }
                else
                {
                    parent.sag = successor;
                }
                successor.sol = current.sol;
            }
            return(true);
        }
Exemplo n.º 11
0
 public OtelAgaci(BTDugumu kokDugum)
 {
     this.kok = kokDugum;
 }