uses wincrt;
var i,n,j : integer;
a: array [1..1000] of integer;
procedure bubble;
var z: integer;
begin
for i:= 1 to n-1 do
begin
for j:= n downto i+1 do
begin
if a[j] < a[j-1] then
begin
z:= a[j];
a[j]:= a[j-1];
a[j-1]:=z;
end;
end;
end;
end;
begin
writeln('UAS STRUKTUR DATA YOHAN APRIANDI');
writeln('**********************************************');
write('masukkan jumlah elemen yang di inginkan : '); readln(n);
writeln('**********************************************');
for i:= 1 to n do
begin write('masukan nilai ke-1:'); readln(a[i]);
end;
bubble;
writeln('************************');
writeln('hasil pengurutan larik : ');
writeln('************************');
for j:=1 to n do
write (a[j],' ');
end.
2.BINARY SEARCH
program searching;
uses wincrt;
label awal;
var pil:char;
lg :char;
const
nmin = 1;
nmax = 100;
type
arrint = array [nmin..nmax] of integer;
var
x : integer;
tabint : arrint;
n,i : integer;
indeks : integer;
function seqsearch1(xx : integer): integer;
var i : integer;
begin
i := 1;
while ((i<n) and (tabint[i] <> xx)) do
i:=i+1;
if tabint[i] = xx then
seqsearch1:=i
else
seqsearch1:=0;
end;
begin
clrscr;
write('masukan jumlah data: '); readln(n);
for i:=1 to n do
begin
write('masukan isi lirik ke-1: '); readln(tabint[i]);
end;
write('inputkan data yang ingin di cari: '); readln(x);
indeks:=seqsearch1(x);
if indeks <> 0 then
write(' data inputan di temukan di larik ke-',indeks)
else
write(x,' tidak ditemukan');
writeln;
writeln;
end.
uses wincrt;
label awal;
var pil:char;
lg :char;
const
nmin = 1;
nmax = 100;
type
arrint = array [nmin..nmax] of integer;
var
x : integer;
tabint : arrint;
n,i : integer;
indeks : integer;
function seqsearch1(xx : integer): integer;
var i : integer;
begin
i := 1;
while ((i<n) and (tabint[i] <> xx)) do
i:=i+1;
if tabint[i] = xx then
seqsearch1:=i
else
seqsearch1:=0;
end;
begin
clrscr;
write('masukan jumlah data: '); readln(n);
for i:=1 to n do
begin
write('masukan isi lirik ke-1: '); readln(tabint[i]);
end;
write('inputkan data yang ingin di cari: '); readln(x);
indeks:=seqsearch1(x);
if indeks <> 0 then
write(' data inputan di temukan di larik ke-',indeks)
else
write(x,' tidak ditemukan');
writeln;
writeln;
end.
0 KOMENTAR