NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

/*
3. “40, 30, 20, 60, 80, 100, 120,140, 136, 130”
sayılarını ikili arma ağacı(Binary Search Tree)’na ekleme,
silme,
arama,
ağacı yazdırma,
en büyük düğümü bulan,
en küçük düğümü bulan fonksiyonları yazarak gerçekleştiriniz.
*/

#include <iostream>
#include <cstdlib>

using namespace std;


#include<bits/stdc++.h>
using namespace std;

struct agac{
int veri;
agac *solcocuk;
agac *sagcocuk;
};
typedef agac dugum;

dugum *yeni_dugum(int deger)
{
dugum *gecici = (dugum *)malloc(sizeof(dugum));
gecici->veri = deger;
gecici->solcocuk = NULL;
gecici->sagcocuk = NULL;
return gecici;
}

dugum* ekle(dugum* kok, int deger)
{

if (kok == NULL) return yeni_dugum(deger);

if (deger < kok->veri)
kok->solcocuk = ekle(kok->solcocuk, deger);
else
kok->sagcocuk = ekle(kok->sagcocuk, deger);

return kok;
}


void yazdir(dugum* kok)
{
if (kok != NULL)
{
yazdir(kok->solcocuk);
cout<< kok->veri << "-";
yazdir(kok->sagcocuk);
}
}



dugum* ara(dugum* kok, int deger)
{
if (kok == NULL || kok->veri == deger)
return kok;

if (kok->veri < deger)
return ara(kok->sagcocuk, deger);

return ara(kok->solcocuk, deger);
}




dugum* en_kucuk_dugum(dugum* kok)
{
dugum* gecici = kok;

while (gecici && gecici->solcocuk != NULL)
gecici = gecici->solcocuk;

return gecici;
}

dugum* en_buyuk_dugum(dugum* kok)
{
dugum* gecici = kok;

while (gecici && gecici->sagcocuk != NULL)
gecici = gecici->sagcocuk;

return gecici;
}




dugum* sil(dugum* kok, int deger)
{
if (kok == NULL) return kok;

if (deger < kok->veri)
kok->solcocuk = sil(kok->solcocuk, deger);


else if (deger > kok->veri)
kok->sagcocuk = sil(kok->sagcocuk, deger);


else
{

if (kok->solcocuk == NULL)
{
dugum *gecici = kok->sagcocuk;
free(kok);
return gecici;
}
else if (kok->sagcocuk == NULL)
{
dugum *gecici = kok->solcocuk;
free(kok);
return gecici;
}

dugum* gecici = en_kucuk_dugum(kok->sagcocuk);

kok->veri = gecici->veri;

kok->sagcocuk = sil(kok->sagcocuk, gecici->veri);
}
return kok;
}


int main()
{

dugum *kok = NULL;
kok = ekle(kok, 50);
kok = ekle(kok, 30);
kok = ekle(kok, 20);
kok = ekle(kok, 40);
kok = ekle(kok, 70);
kok = ekle(kok, 60);
kok = ekle(kok, 80);

cout << "Inorder traversal of the given tree n";
yazdir(kok);

cout<<"nDelete 20n";
kok = sil(kok, 20);
cout<<"Inorder traversal of the modified tree n";
yazdir(kok);

cout<<"nDelete 30n";
kok = sil(kok, 30);
cout<<"Inorder traversal of the modified tree n";
yazdir(kok);

cout<<"nDelete 50n";
kok = sil(kok, 50);
cout<<"Inorder traversal of the modified tree n";
yazdir(kok);

return 0;
}


     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.