0% found this document useful (0 votes)
31 views6 pages

Flowchat System: Manual Atau Random Manual Atau Random

This document contains a Pascal program for sorting algorithms including selection sort and bubble sort. The program allows the user to input a number of data values, select an ascending or descending sort method (selection sort or bubble sort), then displays the data before and after sorting. The selection sort procedures sort in ascending or descending order, while the bubble sort procedures also sort in ascending or descending order. The program demonstrates basic sorting algorithms and allows comparison of results.

Uploaded by

Eri Dwisantika
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views6 pages

Flowchat System: Manual Atau Random Manual Atau Random

This document contains a Pascal program for sorting algorithms including selection sort and bubble sort. The program allows the user to input a number of data values, select an ascending or descending sort method (selection sort or bubble sort), then displays the data before and after sorting. The selection sort procedures sort in ascending or descending order, while the bubble sort procedures also sort in ascending or descending order. The program demonstrates basic sorting algorithms and allows comparison of results.

Uploaded by

Eri Dwisantika
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 6

1.

Flowchat system

START

INPUT N

MENU PILIHAN
METODE

SELECTION SORT SELECTION SORT BUBLE SORT BUBLE SORT


ASCENDING DESCENDING ASCENDING DESCENDING

MANUAL ATAU
RANDOM

MANUAL

RANDOM

INPUT DATA

TAMPILKAN DATA

FINISH
2. Progarm dalam Bahasa Pascal

program Sorting;
uses wincrt;
var data_selection,data_buble:array[1..50] of integer;
n,i,j:byte;
slc,bbl:integer;
pilihan:char;

procedure input_data;
var temp:integer;
pilihan_input:char;
begin
write('masukan jumlah data : ');readln(n);

repeat
clrscr;
write('Apakah menginputkan data secara manual? (Manual=M,
Random=R) :');readln(pilihan_input);
if (pilihan_input='M') then
begin
for i:=1 to n do
begin
write('masukan data yang ke',i,' : ');readln(temp);
data_selection[i]:=temp;
data_buble[i]:=temp;
end;
end
else
if (pilihan_input='R') then
begin
randomize;
for i:=1 to n do
begin
temp:=random(100);
data_selection[i]:=temp;
data_buble[i]:=temp;
end;
end;
until (pilihan_input='M') or (pilihan_input='R');
end;

procedure menu;
begin
repeat
writeln('Menu Pilihan : ');
writeln('------------------------------------------------------');
writeln('A= Sorting dengan Selection Sort Ascending');
writeln('B= Sorting dengan Selection Sort Descending');
writeln('C= Sorting dengan Buble Sort Ascending ');
writeln('D= Sorting dengan Buble Sort Descending');
writeln('------------------------------------------------------');

writeln;writeln;
write('Pilihan menu ? ');readln(pilihan);
until (pilihan='A') or (pilihan='B') or (pilihan='C') or (pilihan='D');
end;

procedure tukar(var a,b:integer);


var c:integer;
begin
c:=a;
a:=b;
b:=c;
end;

procedure selection_sort;
var posisi_min:byte;
begin
for i:=1 to (n-1) do
begin
posisi_min:=i;
for j:=i+1 to n do
begin
if data_selection[j]<data_selection[posisi_min] then
posisi_min:=j;
end;

if posisi_min<>i then
begin
tukar(data_selection[posisi_min],data_selection[i]);
inc(slc);
end;
end;
end;

procedure selection_sort_descending;
var posisi_min:byte;
begin
for i:=1 to (n-1) do
begin
posisi_min:=i;
for j:=i+1 to n do
begin
if data_selection[j]>data_selection[posisi_min] then
posisi_min:=j;
end;

if posisi_min<>i then
begin
tukar(data_selection[posisi_min],data_selection[i]);
inc(slc);
end;
end;
end;

procedure buble_sort;
begin
for i:=1 to n-1 do
begin
for j:=n downto i+1 do
begin
if data_buble[j]<data_buble[j-1] then
begin
tukar(data_buble[j],data_buble[j-1]);
inc(bbl);
end;
end;
end;
end;

procedure buble_sort_descending;
begin
for i:=1 to n-1 do
begin
for j:=n downto i+1 do
begin
if data_buble[j]>data_buble[j-1] then
begin
tukar(data_buble[j],data_buble[j-1]);
inc(bbl);
end;
end;
end;
end;

procedure tampil_data;
begin
clrscr;
if pilihan='A' then
begin
write('Data sebelumnya : ');
for i:=1 to n do
begin
write(data_selection[i]);
write(' ');
end;

writeln;
write('Data hasi pengurutan : ');
selection_sort;
for i:=1 to n do
begin
write(data_selection[i]);
write(' ');
end;
end
else
if pilihan='B' then
begin
write('Data sebelumnya : ');
for i:=1 to n do
begin
write(data_selection[i]);
write(' ');
end;

writeln;
write('Data hasi pengurutan : ');
selection_sort_descending;
for i:=1 to n do
begin
write(data_selection[i]);
write(' ');
end;
end
else
if pilihan='C' then
begin
write('Data sebelumnya : ');
for i:=1 to n do
begin
write(data_buble[i]);
write(' ');
end;

writeln;
write('Data hasi pengurutan : ');
buble_sort;
for i:=1 to n do
begin
write(data_buble[i]);
write(' ');
end;
end
else
if pilihan='D' then
begin
write('Data sebelumnya : ');
for i:=1 to n do
begin
write(data_buble[i]);
write(' ');
end;
writeln;
write('Data hasi pengurutan : ');
buble_sort_descending;
for i:=1 to n do
begin
write(data_buble[i]);
write(' ');
end;
end;

end;

begin
clrscr;
menu;
clrscr;
input_data;
tampil_data;
readln;

end.

You might also like