Posted by : Erick Elfrada Sinurat Selasa, 19 Juni 2012

{program preorder}
uses wincrt;
type
ptr=^Simpul;
simpul=record
data:integer;
kanan,kiri:ptr;
end;
{--------------------------------------------------------------------}
procedure Init(var p:ptr);
begin
p:=nil;
end;
{--------------------------------------------------------------------}
procedure masukdata(var p:ptr; d:integer);
begin
if p=nil then
begin
new(p);
p^.data:=d;
p^.kiri:=nil;
p^.kanan:=nil;
end
else
if p^.data < d then
masukdata(p^.kanan,d)
else
masukdata(p^.kiri,d);
end;
{--------------------------------------------------------------------}
procedure preorder(p:ptr);
15
begin
if p<>nil then
begin
writeln(p^.data);
preorder(p^.kiri);
preorder(p^.kanan);
end;
end;
{--------------------------------------------------------------------}
var
pohon:ptr;
dt :integer;
begin
init(pohon);
repeat
write('Data masuk ke :');readln(dt);
if dt >= 0 then
masukdata(pohon,dt);
until dt<0;
preorder(pohon);
end.
Hasilnya adalah:

Leave a Reply

Subscribe to Posts | Subscribe to Comments

^^Find Me^^

^^Translate^^

^^God Enel^^

^^God Enel^^
My Favorite Anime Character

- Copyright © Elfrada.com - You'll Get it Here-|-Robotic Notes-|-Powered by Blogger -|- Designed by Erick Elfrada -