private int ElemanSayisi(IkiliAramaAgacDugumu dugum) { int count = 0; if (dugum != null) { count = 1; count += ElemanSayisi(dugum.sol); count += ElemanSayisi(dugum.sag); } return(count); }
//Ekleme Islemi public string Ekle(OtelKayit otel) { //Yeni eklenecek dugum icin parent olustur IkiliAramaAgacDugumu tempParent = new IkiliAramaAgacDugumu(); //Kokten basla ve ilerle IkiliAramaAgacDugumu tempSearch = kok; while (tempSearch != null) { //null olana kadar parent a at tempParent = tempSearch; //deger varsa ekleme cik if ((int)tempSearch.veri.Id > otel.Id) { tempSearch = tempSearch.sol; } else { tempSearch = tempSearch.sag; } } //Eklenecek degeri belirt IkiliAramaAgacDugumu eklenecek = new IkiliAramaAgacDugumu(otel); //agac bos ise koke ata if (kok == null) { kok = eklenecek; } else if ((int)tempParent.veri.Id > otel.Id) { tempParent.sol = eklenecek; } else { tempParent.sag = eklenecek; } return(dugumler += eklenecek.veri.Id.ToString() + " "); }
private int maxDepth(IkiliAramaAgacDugumu node) { if (node == null) { return(0); } else { /* compute the depth of each subtree */ int lDepth = maxDepth(node.sol); int rDepth = maxDepth(node.sag); /* use the larger one */ if (lDepth > rDepth) { return(lDepth + 1); } else { return(rDepth + 1); } } }
public IkiliAramaAgacDugumu(OtelKayit veri) { this.veri = veri; sol = null; sag = null; }
private void Ziyaret(IkiliAramaAgacDugumu dugum) { dugumler += dugum.veri.Id + " "; }
public IkiliAramaAgaci(IkiliAramaAgacDugumu kok) { this.kok = kok; }