type tree = ^node;
node = record
inf : char;
brat,son : tree;
end;
var t : tree;
q,data,kuda,shto : char;
c,i : integer;
b : boolean;
procedure dop(var t : tree);
begin
if t^.brat=nil then
begin
new(t^.brat);
writeln('vvedi element');
readln(t^.brat^.inf);
t^.brat^.brat:=nil;
t^.brat^.son:=nil;
end
else dop(t^.brat);
end;
procedure sozd(var t:tree;var data:char);
begin
writeln('vvedite element');
readln(data);
new(t);
t^.inf:=data;
t^.brat:=nil;
t^.son:=nil;
end;
procedure add(var t : tree; data:char);
begin
if t^.inf<>kuda then
begin
if t^.son<>nil then add(t^.son,kuda);
if t^.brat<>nil then add(t^.brat,kuda);
end
else
begin
if t^.son=nil then
begin
new(t^.son);
write('vvedite element:');
readln(t^.son^.inf);
t^.son^.son:=nil;
t^.son^.brat:=nil;
end
else dop(t^.son);
end;
end;
procedure dobavlenie;
begin
write('kuda postavit element?:');
readln(kuda);
add(t,kuda);
end;
procedure print(t:tree; var i:integer);
var j : integer;
begin
write('':i,t^.inf);
if t^.brat<>nil then
begin
print(t^.brat,i);
end;
if t^.son<>nil then
begin
writeln;
print(t^.son,i);
end;
i:=i+1;
end;
begin
while b<>true do
begin
writeln(' 1 - Sozdanie');
writeln(' 2 - Dobavlenie elementa');
writeln(' 3 - Print');
writeln(' 4 - Udalenie');
writeln(' 5 - Exit');
writeln(' 6 - Active');
write('vvedite punkt menu:');
readln(c);
if c=1 then sozd(t,data);
if c=2 then dobavlenie;
if c=3 then print(t,i);
writeln;
writeln('hotite prodoljit?y/n');
readln(q);
if q='y' then b:=false;
if q='n' then b:=true;
if (q<>'y') and (q<>'n') then
begin
writeln('Tolko "n" ili "y"!');
readln(q);
end;
end;
end.