Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApp3
- {
- class Program
- {
- public class Wezel
- {
- public Wezel rodzic;
- public Wezel prawe;
- public Wezel lewe;
- public int wartosc;
- public int numer;
- }
- public class Drzewo : Wezel
- {
- public Wezel root = null;
- public int length = 0;
- public void Push(int liczba)
- {
- var nowy = new Wezel();
- nowy.wartosc = liczba;
- nowy.numer = length + 1;
- if(length == 0)
- {
- root = nowy;
- }
- else
- {
- int tmp = nowy.numer;
- List<int> kierunki = new List<int>();
- while(tmp>1)
- {
- kierunki.Add(tmp % 2);
- tmp /= 2;
- }
- var rodzic = root;
- for(int i=kierunki.Count - 1;i>=1;i--)
- {
- if(kierunki[i]==0)
- {
- rodzic = rodzic.lewe;
- }
- else
- {
- rodzic = rodzic.prawe;
- }
- }
- if (kierunki[0] == 0)
- {
- rodzic.lewe = nowy;
- }
- else
- {
- rodzic.prawe = nowy;
- }
- nowy.rodzic = rodzic;
- }
- length++;
- }
- public void Pop()
- {
- }
- }
- static void Main(string[] args)
- {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement