using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp2
{
class Węzeł
{
public int wartość;
public Węzeł lewy;
public Węzeł prawy;
}
class Drzewo
{
public Węzeł root;
public Drzewo()
{
root = null;
}
public Węzeł Rodzic()
{
return root;
}
public void Push(int id)
{
Węzeł nowy = new Węzeł();
nowy.wartość = id;
if (root == null)
root = nowy;
else
{
Węzeł tmp = root;
Węzeł rodzic;
while (true)
{
rodzic = tmp;
if (id < tmp.wartość)
{
tmp = tmp.lewy;
if (tmp == null)
{
rodzic.lewy = nowy;
return;
}
}
else
{
tmp = tmp.prawy;
if (tmp == null)
{
rodzic.prawy = nowy;
return;
}
}
}
}
}
public void Preorder(Węzeł Root)
{
if (Root != null)
{
Console.Write(Root.wartość + " ");
Preorder(Root.lewy);
Preorder(Root.prawy);
}
}
public void Inorder(Węzeł Root)
{
if (Root != null)
{
Inorder(Root.lewy);
Console.Write(Root.wartość + " ");
Inorder(Root.prawy);
}
}
public void Postorder(Węzeł Root)
{
if (Root != null)
{
Postorder(Root.lewy);
Postorder(Root.prawy);
Console.Write(Root.wartość + " ");
}
}
}
class Program
{
static void Main(string[] args)
{
Drzewo d = new Drzewo();
d.Push(10);
d.Push(5);
d.Push(1);
d.Push(0);
d.Push(2);
d.Push(7);
d.Push(8);
d.Push(15);
d.Push(12);
d.Push(11);
d.Push(20);
Console.WriteLine("Inorder: ");
d.Inorder(d.Rodzic());
Console.WriteLine(" ");
Console.WriteLine();
Console.WriteLine("Preorder: ");
d.Preorder(d.Rodzic());
Console.WriteLine(" ");
Console.WriteLine();
Console.WriteLine("Postorder: ");
d.Postorder(d.Rodzic());
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"}