using System; using System.Collections.Generic; namespace typy_generyczne { class Program { public class Wezel { public Wezel rodzic; public Wezel lewe; public Wezel prawe; public int numer; public T wartosc; public void DodajDziecko(Wezel nowy) { if (nowy.numer % 2 == 0) rodzic.lewe = nowy; else rodzic.prawe = nowy; nowy.rodzic = this; } } class Drzewo { Wezel root=null; int lenght=0; public List DrogaDoRodzica(int numer) { if (numer < 2) throw new Exception("Numer musi byc >=2"); List wynik = new List(); numer = numer / 2; while(numer > 1) { wynik.Add(numer % 2); numer = numer / 2; } wynik.Reverse(); return wynik; } public Wezel ZnajdzRodzica(int numer) { var droga = this.DrogaDoRodzica(numer); Wezel rodzic = this.root; for(int i=0;i nowy = new Wezel(); nowy.wartosc = wartosc; nowy.numer = lenght + 1; if (lenght == 0) { this.root = nowy; return; } var rodzic = this.ZnajdzRodzica(nowy.numer); rodzic.DodajDziecko(nowy); } } static void Main(string[] args) { Console.WriteLine("Hello World!"); Console.ReadLine(); } } } /* do przycisku: Drzewod=new Drzewo */