Home » , , , » Program Bubblesort dengan Pointer

Program Bubblesort dengan Pointer

Written By Unknown on Rabu, 21 Maret 2012 | 20.26



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.
Share this article :

0 komentar:

Posting Komentar

Terimakasih Telah membaca artikel kami. Silahkan tinggalkan komentar anda disini.

 
Support : Dunia Matematika | Dunia Fisik dan Fiksi
Copyright © 2013. Blog Berbagi Ilmu - All Rights Reserved
Template Created by AM Published by Aeroplane
Proudly powered by Blogger