помогите плз с задачей:
"Построить дерево и вывести его повернутым на 90 градусов"
Procedure PrintLex(level: integer; T: TTree);(я надеюсь, у тебя бинарное дерево? Или N-арное?)
Begin
If T = nil Then Exit;
With T^ Do Begin
PrintLex(level + 1, Left);
Writeln('': level*3, Data);
PrintLex(level + 1, Right)
End
End;
17
36 5
11 4 21
uses crt;
type
ttype = integer;
ttree = ^tnode;
tnode = record
Data: ttype;
ix: integer;
left, right: ttree;
end;
procedure Add(var T: ttree; i: ttype; index: integer);
procedure CreateNode(var p: ttree; n: ttype);
begin
new(p);
with p^ do begin
Data := n; ix := index;
left := nil; right := nil
end;
end;
begin
if T <> nil then
with T^ do begin
if Data < i then Add(right, i, index)
else if Data > i then Add(left, i, index)
end
else CreateNode(T, i)
end;
procedure myPrintTree(level: integer; T: ttree; curr: integer);
function find_index(root: ttree; n: integer): ttree;
var check, pp: ttree;
begin
if root <> nil then begin
pp := root;
while pp <> nil do begin
if pp^.ix = n then break;
check := find_index(pp^.left, n);
if check = nil then
check :=find_index(pp^.right, n);
pp := check;
end;
find_index := pp;
end
else find_index := nil;
end;
var found: TTree;
begin
if T = nil then exit;
with T^ do begin
found := find_index(T, curr);
if found <> nil then begin
myPrintTree(level + 1, T, 2 * curr);
Writeln('':3*level, found^.Data);
myPrintTree(level + 1, T, 2 * curr + 1);
end
end
end;
{ main part }
const
size = 6;
iV: array[1 .. size] of ttype = (17, 36, 5, 11, 4, 21);
var
i: integer;
myTree, wasfound: ttree;
begin
myTree := nil;
for i := 1 to size do Add(myTree, iv[i], i);
myPrintdown(1, mytree, 1);
{ delete tree here }
end.
17
36 5
11 4 21
procedure myPrintTree(px: integer;
level: integer; T: ttree; curr: integer);
function find_index(root: ttree; n: integer): ttree;
var check, pp: ttree;
begin
if root <> nil then begin
pp := root;
while pp <> nil do begin
if pp^.ix = n then break;
check := find_index(pp^.left, n);
if check = nil then
check :=find_index(pp^.right, n);
pp := check;
end;
find_index := pp;
end
else find_index := nil;
end;
const
{ Эта константа уменьшает/увеличивает величину отступа между левым и правым потомком }
half = 30;
var found: TTree;
begin
if T = nil then exit;
with T^ do begin
found := find_index(T, curr);
if found <> nil then begin
myPrintTree(px - (half div succ(level)), level + 1, T, 2 * curr);
begin
gotoxy(px, 2 * level);
Writeln(found^.Data:3);
end;
myPrintTree(px + (half div succ(level)), level + 1, T, 2 * curr + 1);
end
end
end;
...
clrscr;
myPrintTree(40, 1, mytree, 1);
...