Posted by : Erick Elfrada Sinurat Selasa, 19 Juni 2012

Program Sorting_Bubble;
Uses winCrt;
Const
Max = 10;
Type
Arr = Array[1..max] Of Byte;
Var
Data : Arr;
i : Byte;
Procedure Input;
Begin
Clrscr;

Writeln('Masukkan 10 Data ');
Writeln('=================');
For I:=1 To Max Do
Begin
Write('Data Ke :',I,'=');Readln(Data[i]);
End;
Clrscr;
For i:=1 to Max Do
Write(Data[i],' ');
Writeln;
Writeln('=========================');
Writeln('Data Yang telah Diurutkan');
Writeln;
{ Readln;}
End;

Procedure Change (Var a,b :Byte);
Var c:Byte;
Begin
C:=a;a:=b;b:=c;
End;
Procedure Asc_Bubble;
Var
P,Q : Byte;
Flag: Boolean;
Begin
Flag:=False;
P:=2;
While (P<Max) And (Not Flag) Do
Begin
Flag:=True;
For Q:=Max Downto P Do
If Data[Q]<Data[Q-1] Then
Begin
Change(Data[Q],data[Q-1]);
Flag:=False;
End;
Inc(i);
End;
Write(' Ascending ');
End;

Procedure Desc_Bubble;
Var
P,Q : Byte;
Flag: Boolean;
Begin
Flag:=False;
P:=2;
While (P<Max) And (Not Flag) Do
Begin
Flag:=True;
For Q:=Max Downto P Do
If Data[Q]>Data[Q-1] Then
Begin
Change(Data[Q],data[Q-1]);
Flag:=False;
End;
Inc(i);
End;
Write('Descending ');
End;
Procedure Output;
Begin
For I:=1 To Max Do
Write(Data[I],' ');
Writeln;
End;
Begin
Input;
Asc_Bubble; Output;
Desc_Bubble; OutPut;
Writeln;
Write('Tekan Enter Untuk Lanjut');
Readln;
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 -