using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp4
{
class Wezel
{
public int wartosc;
public Wezel lewy;
public Wezel prawy;
public void pokaz()
{
Console.Write("[");
Console.Write(wartosc);
Console.Write("]");
}
}
class Tree
{
public Wezel korzen;
public Tree()
{
korzen = null;
}
public Wezel ZwrocKorzen()
{
return korzen;
}
public void Wstaw(int id)
{
Wezel newWezel
= new Wezel
();
newWezel.wartosc = id;
if (korzen == null)
korzen = newWezel;
else
{
Wezel obecny = korzen;
Wezel rodzic;
while (true)
{
rodzic = obecny;
if (id < obecny.wartosc)
{
obecny = obecny.lewy;
if (obecny == null)
{
rodzic.lewy = newWezel;
return;
}
}
else
{
obecny = obecny.prawy;
if (obecny == null)
{
rodzic.prawy = newWezel;
return;
}
}
}
}
}
public void Preorder(Wezel Root)
{
if (Root != null)
{
Console.Write(Root.wartosc + " ");
Preorder(Root.lewy);
Preorder(Root.prawy);
}
}
public void Inorder(Wezel Root)
{
if (Root != null)
{
Inorder(Root.lewy);
Console.Write(Root.wartosc + " ");
Inorder(Root.prawy);
}
}
public void Postorder(Wezel Root)
{
if (Root != null)
{
Postorder(Root.lewy);
Postorder(Root.prawy);
Console.Write(Root.wartosc + " ");
}
}
}
class Program
{
static void Main(string[] args)
{
Test.Wstaw(14);
Test.Wstaw(33);
Test.Wstaw(67);
Test.Wstaw(43);
Test.Wstaw(32);
Test.Wstaw(88);
Test.Wstaw(43);
Test.Wstaw(32);
Test.Wstaw(12);
Test.Wstaw(32);
Test.Wstaw(54);
Test.Wstaw(32);
Test.Wstaw(65);
Test.Wstaw(13);
Console.WriteLine("Inorder : ");
Test.Inorder(Test.ZwrocKorzen());
Console.WriteLine(" ");
Console.WriteLine();
Console.WriteLine("Preorder : ");
Test.Preorder(Test.ZwrocKorzen());
Console.WriteLine(" ");
Console.WriteLine();
Console.WriteLine("Postorder : ");
Test.Postorder(Test.ZwrocKorzen());
Console.WriteLine(" ");
Console.ReadLine();
}
}
}
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}