program mengurutkan_bilangan;
uses crt;
type
Data = array [1..100] of integer;
var
y,x:array[1..100] of integer;
a,b,n,i,c,temp:integer;
Procedure Quick(Var Temp : Data ; Awal, Akhir : Integer);
Var
I,J : Integer;
Procedure ATUR;
Begin
I:=Awal +1;
J:= Akhir;
While Temp[I] < Temp[Awal] Do Inc(I);
While Temp[J] > Temp[Awal] Do Dec(J);
While I < J Do
Begin
SWAP(Temp[I],Temp[J]);
While Temp[I] < Temp[Awal] Do Inc(I);
While Temp[J] > Temp[Awal] Do Dec(J);
End;
SWAP(Temp[Awal], Temp[J]);
End;
Begin
If Awal < Akhir Then
Begin
ATUR;
Quick(Temp, Awal, J-1);
Quick(Temp,J+1,Akhir);
End;
End;
Procedure SWAP(Var A,B : Char);
Var
Temp : Char;
Begin
Temp := A;
A := B;
B := Temp;
End;
begin
clrscr;
writeln('************* Selamat Datang ************');
writeln('** Program Mengurutkan n buah bilangan **');
writeln('************ Selamat bekerja ************');
writeln;
write('Masukkan banyak bilangan : ');
readln(n);
writeln;
for i:=1 to n do
begin
write('Masukkan bilangan ke-',i,' : ');
readln(y[i]);
end;
QUICK(y,n);
writeln;
writeln('Berikut bilangan yang telah urut :');
for i:=1 to n do
writeln('Bilangan ke-',i,' : ',y[i]);
readln;
end.
Senin, 27 Desember 2010
Sintaks / Listing / Script Program Sorting Quick Sort
08.32
Ariana
No comments
0 comments:
Posting Komentar