Sambil di koreksi juga ya... :D
program tree_dinamis;
uses crt;
type pohon=^node;
node=record
data:integer;
kiri,kanan:pohon;
end;
var T:pohon;
info:integer;
{----------------------------------------}
Procedure Buat_BST(info:integer;var T:pohon);
var
b:pohon;
begin
if T=nil then
begin
new(b);b^.data:=info;b^.kiri:=nil;b^.kanan:=nil;
T:=b;
end
else
begin
if T^.data
Buat_BST(info,T^.kiri);
end;
end;
{-------------------------------------------}
Procedure Baca_BST_pre(b:pohon);
begin
if (b<>nil)then
begin
write(b^.data);
Baca_BST_pre(b^.kiri);
Baca_BST_pre(b^.kanan);
end;
end;
Procedure Baca_BST_in(b:pohon);
begin
if (b<>nil)then
begin
Baca_BST_in(b^.kiri);
write(b^.data);
Baca_BST_in(b^.kanan);
end;
end;
{-----------------------------------------}
Procedure Baca_BST_post(b:pohon);
begin
if(b<>nil)then
begin
Baca_BST_post(b^.kiri);
Baca_BST_post(b^.kanan);
write(b^.data);
end;
end;
{-----------------------------------------}
begin
clrscr;
new(T);T^.kiri:=nil;T^.kanan:=nil;
writeln('Masukan Data kedalam tree');
repeat
write('nilai data :');readln(info);
if info<>0 then Buat_BST(info,T);
until info=0;
writeln;
readln;
writeln('Pembacaan secara pre order');
Baca_BST_pre(T);
writeln;
readln;
writeln('Pembacaan secara in order');
Baca_BST_in(T);
writeln;
readln;
writeln('Pembacaan secara post order');
Baca_BST_post(T);
writeln;
readln;
end.
Devvout n Degassu™
Tidak ada komentar:
Posting Komentar