program bubblesortdenganpointer;
uses wincrt;
type ptr=^z;
z=record
x:integer;
next:ptr;
end;
var
prtm : ptr;
b,c : integer;
procedure pointer (x:integer;var prtm:ptr);
var
baru :ptr;
begin
new
(baru);
baru^.x := x;
baru^.next:= prtm;
prtm:= baru;
end;
procedure bubbsort (prtm:ptr);
var
dt,dt2 : ptr;
m: integer;
begin
dt := prtm;
while dt<> nil do
begin
dt2 := dt^.next;
while dt2 <> nil do
begin
if dt^.x < dt2^.x then
begin
m:= dt^.x;
dt^.x := dt2^.x;
dt2^.x := m;
end;
dt2 := dt2^.next;
end;
dt:= dt^.next;
end;
end;
procedure muncul (prtm:ptr);
var
dt :ptr;
begin
dt:= prtm;
while dt <> nil do
begin
write (dt^.x,' ');
dt := dt^.next;
end;
end;
begin
repeat
write('Input angka: ');readln(b);
if b<>0 then
begin
pointer(b,prtm);
end;
until b=0;
write('Deret angka: ');
bubbsort(prtm);
muncul(prtm);
end.
0 komentar:
Posting Komentar
Terimakasih Telah membaca artikel kami. Silahkan tinggalkan komentar anda disini.