Sunday, 23 December 2012

Belajar contoh program pascal counting sort, selection sort, insertion sort, dan bubble sort.

Hari ini saya akan memberikan beberapa contoh source code sorting pada program pascal. Untuk keterangan dan teorinya tidak saya berikan karena sudah banyak di Google search. Bisa anda cari sendiri.  lihat tutorial dibawah ini.


1. Counting Sort


program counting_sort;

uses wincrt;
type
nilai = array[1..50] of integer;
var
nl : nilai;
mindata,maxdata: integer;
jumlah ,i:integer;
procedure isinilai(var nl:nilai; var n:integer);
var
j:integer;
begin
write('banyak data : ');
readln(n);
for j:=1 to n do
begin
write('data ke ',j,' : ');
readln(nl[j]);
end;
end;

procedure minmax(nl:nilai;n:integer;var mindata:integer;var maxdata:integer);

begin
mindata :=nl[1];
maxdata :=nl[1];
for i:=2 to n do
begin
if nl[i] < mindata then mindata :=nl[i];
if nl[i] > maxdata then maxdata :=nl[i];
end;
end;

procedure countsort(var tabint:nilai;n:integer;mindata:integer;maxdata:integer);

const min=1;max=100;
var
i,j,k:integer;
tabcount:array [min..max] of integer;
begin
for i:=mindata to maxdata do
tabcount[i]:=0;

for i:=1 to n do

tabcount[tabint[i]]:=tabcount[tabint[i]]+1;
k:=0;
for i :=mindata to maxdata do
if tabcount[i]<>0 then
for j:=1 to tabcount[i] do
begin
k:=k+1;
tabint[k]:=i;
end;
end;

procedure cetak(nl:nilai;n:integer);

begin
for i:=1 to n do
write(nl[i],' ');
writeln;
end;

begin

isinilai(nl,jumlah);
minmax(nl,jumlah,mindata,maxdata);
writeln('ini data sebelum diurutkan: ');
cetak(nl,jumlah);
countsort(nl,jumlah,mindata,maxdata);
writeln('ini data setelah diurutkan: ');
cetak(nl,jumlah);
readln;
end.





2. Insertion Sort

program insertion(input,output);
const
MAX = 100;
var
a : array[1..MAX] of integer;
i, n : integer;

procedure insertion_sort;
var
i, pos : integer;
nilai : integer;
tanda : boolean;
begin
for i := 2 to n do
begin

nilai := a[i];
pos := i;
tanda := false;
while not tanda do
begin
if pos <= 1 then
tanda := true
else if nilai >= a[pos-1] then
tanda := true
else
begin
a[pos] := a[pos-1];
pos := pos-1
end
end; {while}

a[pos] := nilai;

end {for}
end;

begin { main }
write('Masukkan banyak data (max=',MAX:2,') : ');
readln(n);

writeln('Masukkan Angka sebanyak ',n:1,' : ');
for i := 1 to n do
read(a[i]);

insertion_sort;

for i := 1 to n do
write(a[i]:1,' ');
readln;
writeln;
readln;
end.


3. Selection Sort

program selectionsort;
uses crt;
var
angka: array[1..5] of integer;
i,a,n,temp: integer;
begin
clrscr;
write('masukkan banyak data: ');
readln(n);
for i:=1 to n do
begin
write('masukkan angka ke',i,' = ');
readln(angka[i]);
end;
writeln;

{Tampilkan data sebelum diurutkan}
writeln('Sebelum diurutkan : ');
for i:=1 to n do
begin
writeln('angka ke-', i, ' : ', angka[i]);
end;

{Lakukan pengurutan/sorting}
for i:=1 to n-1 do
begin
for a:=i+1 to n do
begin
if(angka[a] < angka[i]) then
begin
temp := angka[a];
angka[a] := angka[i];
angka[i] := temp;
end;
end;
end;

{Tampilkan data setelah diurutkan}
writeln('Setelah diurutkan : ');
for i:=1 to n do
begin
writeln('angka ke-', i, ' : ', angka[i]);
readln;
end;
readln;
end.



4. Bubble Sort

Program Bubble_Sort;
Uses Crt;
const
max = 100;
type
Larik = array [1..max] of integer;
var
A: Larik;
I: integer;
N: integer;
pil:byte;

procedure Jumlah_Data;
begin
write('Masukkan banyaknya data = '); readln(N);
writeln;
end;
procedure Input;
var
I: integer;
begin
for I:=1 to N do
begin
write('Masukkan data ke- ', I, ' = '); readln(A[I]);
end;
end;

procedure Change(var A, B: integer);
var
T: integer;
begin
T:=A;
A:=B;
B:=T;
end;

procedure asc_buble;
var
p,q :INTEGER;
flag:boolean;
begin
flag:=false;
p:=2;
while (p
begin
flag:=true;
for q:=N downto p do
if A[q]
begin
change(A[q],A[q-1]);
flag:=false;
end;
inc(i);
end;
writeln;
write('Data Diurutkan Secara Ascending: ');
end;

procedure desc_buble;
var
p,q :byte;
flag:boolean;
begin
flag:=false;
p:=2;
while (p
begin
flag:=true;
for q:=max downto p do
if A[q]>A[q-1] then
begin
change(A[q],A[q-1]);
flag:=false;
end;
inc(i);
end;
writeln;
write('Data Diurutkan Secara Descending: ');
end;

procedure Output;
var
i: integer;
begin
for i:=1 to N do
write(A[i], '  ');
writeln;
end;

begin
Jumlah_Data;
input;
clrscr;
writeln('[1].pengurutan secara Ascending');
writeln('[2].pengurutan secara Descending');
write('Silahkan Masukkan Pilihan Anda = ');readln(pil);
case pil of
1:asc_buble;

2:desc_buble;
end;
output;
readln;
end.

Input


Output





Monday, 17 December 2012

Tuesday, 6 November 2012

Maher Zain - The Chosen One




In the time of darkness and greedIt is your light that we needYou came to teach us how to liveMuhammad Ya Rasool Allah
You were so caring and kindYour soul was full of lightYou are the best of mankindMuhammad Khairu KhalqillahSallu 'ala Rasulillah, Habibil MustafaPeace be upon The MessengerThe Chosen One
From luxury you turned awayAnd all night you would prayTruthful in every word you sayMuhammad Ya Rasul Allah
Your face was brighter than the sunYour beauty equalled by noneYou are Allah's Chosen OneMuhammad Khairu KhalqillahSallu 'ala Rasulillah, Habibil MustafaPeace be upon The MessengerThe Chosen One
I will try to follow your wayAnd do my best to live my lifeAs you taught meI pray to be close to you
On that day and see you smileWhen you see meSallu 'ala Rasulillah, Habibil MustafaPeace be upon The MessengerThe Chosen OneSallu 'ala Rasulillah, Habibil MustafaPeace be upon The MessengerThe chosen one

Maher Zain - Awaken




We were given so many prizesWe changed the desert into oasisWe built buildings of different lengths and sizesAnd we felt so very satisfiedWe bought and boughtWe couldn't stop buyingWe gave charity to the poor 'causeWe couldn't stand their cryingWe thought we paid our duesBut in factTo ourselves we're just lying
Chorus :OhI'm walking with my head lowered in shame from my placeI'm walking with my head lowered from my raceYes it's easy to blame everything on the westWhen in fact all focus should be on ourselves
We were told what to buy and we'd boughtWe went to London, Paris andWe made show we were seen in the most exlcusive shopsYes we felt so very satisfied
We felt our money gave us infinite power
We forgot to teach our children about history and honorWe didn't have any time to loseWhen we were.. (were)So busy feeling so satisfied
Chorus :I'm walking with my head lowered in shame from my placeI'm walking with my head lowered from my raceYes it's easy to blame everything on the westWhen in fact all focus should be on ourselves
We became the visuals without a souldespite the heatOur homes felt so empty and coldTo fill the emptinessWe bought and boughtMaybe all the fancy carsAnd bling will make us feel satisfiedMy dear brother and sisterIt's time to change insideOpen your eyesDon't throw away what's right asideBefore the day comesWhen there's nowhere to run and hideNow ask yourself 'cause Allah's watching you
Is He satisfied?Is Allah satisfied?Is Allah satisfied?Is Allah satisfied?
Chorus :OhI'm walking with my head lowered in shame from my placeI'm walking with my head lowered from my raceYes it's easy to blame everything on the westWhen in fact all focus should be on ourselves

Saturday, 3 November 2012

Jesse Mccartney - Just So You Know

I shouldn't love you but I want toI just can't turn awayI shouldn't see you but I can't moveI can't look away
I shouldn't love you but I want toI just can't turn awayI shouldn't see you but I can't moveI can't look away
And I don't knowHow to be fine when I'm not'Cause I don't knowHow to make a feeling stop
Just so you knowThis feeling's takin' controlOf me and I can't help itI won't sit aroundI can't let him win now
Thought you should knowI've tried my best to let goOf you but I don't want toI just gotta say it all before I goJust so you know
It's gettin' hard to be around youThere's so much I can't sayDo you want me to hide the feelingsAnd look the other away
And I don't knowHow to be fine when I'm not'Cause I don't knowHow to make a feeling stop
Just so you knowThis feeling's takin' controlOf me and I can't help itI won't sit aroundI can't let him win now
Thought you should knowI've tried my best to let goOf you but I don't want toI just gotta say it all before I goJust so you know
This emptiness is killin' meAnd I'm wonderin' why I've waited so longLookin' back I realize it was always thereJust never spoken
I'm waitin' hereBeen waitin' here
Just so you knowThis feeling's takin' controlOf me and I can't help itI won't sit aroundI can't let him win now
Thought you should knowI've tried my best to let goOf you but I don't want toJust gotta say it all before I goJust so you know, just so you know
Thought you should knowI've tried my best to let goOf you but I don't want toJust gotta say it all before I goJust so you know,Just so you know

The Cutest One

I will share photos the cutest one that I like the most.. ^o^
And it is...

TARAAA!!! It's DANBO.. I love him so much :D














David Archuleta - Wait


I can't sleep I'm feeling wide awakeTonight is taking it's timeHow much more before the morning breaksAnd I can leave it all behind'Cause every time I try to close my eyesI only end up seeing memories of youAnd it's never enough I'm waiting
Even though you're gone I can hear your heartIt's calling out my name like a flash in the darkIf this is just a dreamI won't give it backI'll find a way to make it lastOne more minute wait wait wait don't goJust one more minute wait wait wait don't go
I am keeping every word you sayBut how much longer can I hold onCause whispers echoing until they fadeRemind me that you're already gone'Cause every time I try to chase your voiceI end up getting lost and running in circlesAnd it's never enough I'm waiting
Even though you're gone I can hear your heartIt's calling out my name like a flash in the darkIf this is just a dreamI won't give it backI'll find a way to make it lastOne more minute wait wait wait don't goJust one more minute wait wait wait don't goWait wait wait don't goJust one more minute wait wait wait don't goOooh yeah don't go
Even though you're gone I can hear your heartIt's calling out my name like a flash in the darkIf this is just a dreamI won't give it backI'll find a way to make it lastOne more minute wait wait wait don't goJust one more minute wait wait wait don't go