using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp10 { public class DrzewoBST { BST root = null; BST tmp; int dlugosc = 0; public void Push(int liczba) { BST nowy = new BST(); nowy.wartosc = liczba; tmp = root; if (root == null) root = nowy; else{ tmp = root; if (nowy.wartosc < tmp.wartosc) { while (tmp.lewe != null) { tmp = tmp.lewe; } tmp.lewe = nowy; dlugosc++; } if (nowy.wartosc > tmp.wartosc) { while (tmp.prawe != null) { tmp = tmp.prawe; } tmp.prawe = nowy; dlugosc++; } } } public void Pop(int liczba) { tmp = root; while(tmp != null) { tmp = tmp.lewe; if (root.wartosc == liczba) { Console.WriteLine("FOUND"); tmp = null; } } } public void Lenght() { Console.WriteLine("Ilosc: " + dlugosc); } public void Show() { Console.WriteLine("--------------------"); Pokaz(root); } public void Pokaz(BST Root) { if (Root != null) { Console.WriteLine(Root.wartosc); Pokaz(Root.lewe); Pokaz(Root.prawe); } } } public class BST { public BST lewe; public BST prawe; public int wartosc; } class Program { static void Main(string[] args) { DrzewoBST Drzewo = new DrzewoBST(); Drzewo.Push(8); Drzewo.Push(5); Drzewo.Push(12); Drzewo.Push(7); Drzewo.Push(4); Drzewo.Push(15); Drzewo.Push(11); Drzewo.Show(); Drzewo.Pop(4); Drzewo.Show(); Console.ReadLine(); } } }