program linkedlist2;
uses crt;
type data = record
nama,npm,tgl : array[1..10]of string;
alamat,link: array[1..10]of integer;
end;
var list: array[1..10]of integer;
asc,desc : array[1..10]of string;
mhs : data;
avail,i,isi,opsi,del,start,temp,temp2,ujung: integer;
procedure Ascending;
var x, y, Imax : integer;
Smax, temp3 : string;
begin
for x := 1 to 10 do
begin
Smax := asc[x];
for y := x to 10 do
begin
if (asc[y] <= Smax) then
begin
Smax := asc[y];
Imax := y;
end;
end;
temp3 := asc[x];
asc[x] := asc[Imax];
asc[Imax] := temp3;
end;
end;
procedure Descending;
var x, y, Imin : integer;
Smin, temp4 : string;
begin
for x := 1 to 10 do
begin
Smin := desc[x];
for y := x to 10 do
begin
if (desc[y] >= Smin) then
begin
Smin := desc[y];
Imin := y;
end;
end;
temp4 := desc[x];
desc[x] := desc[Imin];
desc[Imin] := temp4;
end;
end;
procedure cekavail;
var j : integer;
begin
for j:=1 to 10 do
begin
if mhs.link[avail]=0 then
begin
temp:=0;
break;
end
else if mhs.link[avail]=mhs.alamat[j] then
begin
if mhs.nama[j]='' then
begin
temp:=j;
break;
end;
end;
end;
end;
procedure menu;
begin
clrscr;
writeln(' PROGRAM LINKED LIST (MENGGUNAKAN AVAIL)');
writeln(' |Alamat| Nama | NPM | Tgl.Lahir | Link |');
for i := 1 to 10 do
begin
asc[i]:=mhs.nama[i];
desc[i]:=mhs.nama[i];
mhs.alamat[i]:=i;
gotoxy(10,i+2);write('|',mhs.alamat[i]);
gotoxy(17,i+2);write('|',mhs.nama[i]);
gotoxy(24,i+2);writeln('|',mhs.npm[i]);
gotoxy(32,i+2);writeln('|',mhs.tgl[i]);
gotoxy(44,i+2);writeln('| ',mhs.link[i],' |');
end;
if isi=0 then
begin
avail:=3;
start:=3;
end
else
begin
avail:=temp;
for i:=1 to isi do
begin
if list[i]<>0 then
begin
start:=list[i];
break;
end;
end;
end;
if avail<>0 then
begin
gotoxy(52,avail+2);write(' << AVAIL ');
end;
gotoxy(1,start+2);write('START >> ');
list[isi+1]:=avail;
gotoxy(1,13);writeln('AVAIL : ',avail);
gotoxy(1,14);writeln('1. List ');
gotoxy(1,15);writeln('2. Insert ');
gotoxy(1,16);writeln('3. Delete ');
gotoxy(14,14);writeln('4. Ascending Sort ');
gotoxy(14,15);writeln('5. Descending Sort ');
gotoxy(14,16);writeln('6. Exit ');
write('Select your choice : ');readln(opsi);
if opsi =1 then
begin
if isi=0 then
begin
writeln('THERE IS NO DATA !');
readln;
menu;
end
else
begin
for i:=1 to isi do
begin
if list[i]<>0 then
begin
write('[',mhs.nama[list[i]],']');
if i<>isi then write(' >> ');
end;
end;
readln;
menu;
end;
end
else if opsi =2 then
begin
if (avail=0) then
begin
writeln('ERROR : DATA OVERFLOW');
readln;
menu;
end
else
begin
inc(isi);
write('Masukkan nama : ');readln(mhs.nama[avail]);
write('Masukkan npm : ');readln(mhs.npm[avail]);
write('Masukkan tanggal lahir : ');readln(mhs.tgl[avail]);
temp2:=avail;
if isi<>1 then mhs.link[list[isi-1]]:=temp2;
cekavail;
mhs.link[avail]:=0;
menu;
end;
end
else if opsi =3 then
begin
if isi=0 then
begin
writeln('ERROR: DATA UNDERFLOW');
readln;
menu;
end
else
begin
write('Data pada alamat keberapa yang akan dihapus ? ');readln(del);
mhs.nama[del]:='';mhs.npm[del]:='';mhs.tgl[del]:='';
for i:=1 to 10 do
begin
if mhs.link[i]=del then
begin
mhs.link[i]:=mhs.link[del];
break;
end;
end;
mhs.link[del]:=0;
mhs.link[ujung]:=del;
ujung:=del;
for i:=1 to 10 do
begin
if list[i]=del then
begin
list[i]:=0;
break;
end;
end;
menu;
end;
end
else if opsi=4 then
begin
ascending;
for i:= 1 to 10 do
begin
if asc[i]<>'' then
begin
write('[',asc[i],']');
if i<>10 then write(' >> ');
end;
end;
readln;
menu;
end
else if opsi=5 then
begin
descending;
for i:= 1 to 10 do
begin
if desc[i]<>'' then
begin
write('[',desc[i],']');
if i<>10 then write(' >> ');
end;
end;
readln;
menu;
end;
end;
begin {program utama}
isi:=0;
mhs.link[1]:=7;
mhs.link[2]:=4;
mhs.link[3]:=5;
mhs.link[4]:=10;
mhs.link[5]:=1;
mhs.link[6]:=8;
mhs.link[7]:=9;
mhs.link[8]:=0;
mhs.link[9]:=2;
mhs.link[10]:=6;
ujung:=8;
menu;
end.
Tuesday, December 18, 2012
Monday, December 17, 2012
PROGRAM PASCAL SELECTION SORTING
program Selection;
uses crt;
var input : array [1..10] of integer;
banding,tukar,jumlah,i,j,k,l,temp:integer;
begin
clrscr;
writeln('PROGRAM TEKNIK SELECTION');
write('Masukkan jumlah data , maksimal 10 : ');readln(jumlah);
for i := 1 to jumlah do
begin
write('Masukkan data ke -',i,' : ');readln(input[i]);
end;
for j:= 1 to jumlah-1 do
begin
k := j;
for l := j+1 to jumlah do
begin
if input[k] > input[l] then
begin
k := l;
end;
banding:=banding+1;
end;
temp:=input[k];
input[k] := input[j];
input[j] := temp;
tukar:=tukar+1;
end;
for i:= 1 to jumlah do
begin
write('Data ke -',i,' yang sudah di sortir : ');writeln(input[i]);
end;
write('Jumlah perbandingan : ');writeln(banding);
write('Jumlah pertukaran : ');writeln(tukar);
readln;
end.
uses crt;
var input : array [1..10] of integer;
banding,tukar,jumlah,i,j,k,l,temp:integer;
begin
clrscr;
writeln('PROGRAM TEKNIK SELECTION');
write('Masukkan jumlah data , maksimal 10 : ');readln(jumlah);
for i := 1 to jumlah do
begin
write('Masukkan data ke -',i,' : ');readln(input[i]);
end;
for j:= 1 to jumlah-1 do
begin
k := j;
for l := j+1 to jumlah do
begin
if input[k] > input[l] then
begin
k := l;
end;
banding:=banding+1;
end;
temp:=input[k];
input[k] := input[j];
input[j] := temp;
tukar:=tukar+1;
end;
for i:= 1 to jumlah do
begin
write('Data ke -',i,' yang sudah di sortir : ');writeln(input[i]);
end;
write('Jumlah perbandingan : ');writeln(banding);
write('Jumlah pertukaran : ');writeln(tukar);
readln;
end.
Friday, December 14, 2012
PROGRAM PASCAL TEKNIK EXCHANGE SORTING
program Exchange;
uses crt;
var input : array [1..10] of integer;
banding,tukar,jumlah,i,j,k,temp:integer;
begin
clrscr;
writeln('PROGRAM TEKNIK EXCHANGE');
write('Masukkan jumlah data , maksimal 10 : ');readln(jumlah);
for i := 1 to jumlah do
begin
write('Masukkan data ke -',i,' : ');readln(input[i]);
end;
for j:= 1 to jumlah do
begin
for k:= j+1 to jumlah do
begin
banding:=banding+1;
if input[j]>input[k] then
begin
temp:=input[k];
input[k]:=input[j];
input[j]:=temp;
tukar:=tukar+1;
end;
end;
end;
for i:= 1 to jumlah do
begin
write('Data ke -',i,' yang sudah di sortir : ');writeln(input[i]);
end;
write('Jumlah perbandingan : ');writeln(banding);
write('Jumlah pertukaran : ');writeln(tukar);
readln;
end.
uses crt;
var input : array [1..10] of integer;
banding,tukar,jumlah,i,j,k,temp:integer;
begin
clrscr;
writeln('PROGRAM TEKNIK EXCHANGE');
write('Masukkan jumlah data , maksimal 10 : ');readln(jumlah);
for i := 1 to jumlah do
begin
write('Masukkan data ke -',i,' : ');readln(input[i]);
end;
for j:= 1 to jumlah do
begin
for k:= j+1 to jumlah do
begin
banding:=banding+1;
if input[j]>input[k] then
begin
temp:=input[k];
input[k]:=input[j];
input[j]:=temp;
tukar:=tukar+1;
end;
end;
end;
for i:= 1 to jumlah do
begin
write('Data ke -',i,' yang sudah di sortir : ');writeln(input[i]);
end;
write('Jumlah perbandingan : ');writeln(banding);
write('Jumlah pertukaran : ');writeln(tukar);
readln;
end.
Wednesday, December 12, 2012
Dragon Nest T4 lv 50 Crusader PvE/PvP Hybrid Build
Today i will post about my once favored game, Dragon Nest. My first char was a Cleric and advance into Paladin, and later on 50 cap become a Crusader. This build is my own preference for casual PvP and PvE players. This is not the best nor the worst, because all builds have their weaknesses and strong point, hence i believed the best build is the build that you build by your own preference.
Crusader is a Cleric's 3rd job and advanced from a Paladin. All Crusader skills are focused more as DPS and losing its path through defence. If you want more tanky and stunny(justice crash) you can choose Guardian as your 3rd job. Here is a quick link of my build, you can see damage, cooldown and all other info in this skill calculator :
http://dnarmory.com/skill-calc?i=4-20-42-50#AnGEX.kNjXgWp_obN84H
You can build your very own Crusader build, following this link:
http://dnarmory.com/skill-calc?i=4-20-42-60
Here is my build picture :
Here's my quick explanation on my build :
1st - Cleric's tree
Ok thats all i hope you guys get something useful from this post, thank you :D
Crusader is a Cleric's 3rd job and advanced from a Paladin. All Crusader skills are focused more as DPS and losing its path through defence. If you want more tanky and stunny(justice crash) you can choose Guardian as your 3rd job. Here is a quick link of my build, you can see damage, cooldown and all other info in this skill calculator :
http://dnarmory.com/skill-calc?i=4-20-42-50#AnGEX.kNjXgWp_obN84H
You can build your very own Crusader build, following this link:
http://dnarmory.com/skill-calc?i=4-20-42-60
Here is my build picture :
Here's my quick explanation on my build :
1st - Cleric's tree
- Lv 1 Righteous Bolt : a requirement for Lightning Zap(Paladin's Tree).
- Lv 1 Paralyze Bolt : i think you already know how useful this skill is in PvP.
- Lv 1 Dive Kick : to catch opponet that are far from you, and continue your combos.
- Lv 6 Sliding Knee Kick : lv 6 of this will give you extra kick when activated, and for me its very useful for bouncing your opponet again for continuation of combos.
- Lv 4 Block : Super useful in PvE and PvP Comp ON (not softban).
- Lv 8 Heal : Okay. I think you guys agreed to max it :)
- Lv 4 Toughness, Lv 4 Aerial Evasion, Lv 5 Sliding Step, Lv 1 Mental Fortitude, Lv 3 Attituned Mind : passives are useful in pvp, and for me i like regeneration more than maxing the mp pool.
- Lv 12 Holy Relic : i think its one of a main DPS for crusaders. short cooldown, and Holy Relic EX will give you more wide area and 50% damage. And also you can change your Relic-EX placement during casting, not like the non-EX version.
- Lv 6 Lightning Zap : i just take it lv 6 because it gives much damage on lv 6 as the skill damage amplifies. I personally dont think to max it because warriors can easily use "Relieve" and your lightning zap would be useless on pvp.
- Lv 7 Electric Smite : a must-maxed skill. main DPS skill for all paladins. and a super armor breaker.
- Lv 6 Armor Break : same as Smite, this one has a short cooldown and a medium super armor breaker.
- Lv 4 Auto BLock : helps you from being combo'ed by the other player , by luck :)
- Lv 3 Elemental Aura : i think its useful both in pve and pvp(againts elemental lords).
- Lv 2 Conviction Aura : very useful for a solo player and 1vs1.
- The others lv 1 i think not worth spending SP on those skills. Shield Charge is just for mobility and flinching. Just sacred hammering who is worth SP-spending on the next 60 cap, because of Sacred Hammering EX. However sacred hammering has a long cooldown on pvp, so i found it not so useful.
- Lv 1 Judgement Hammer : medium-armor breaker, low damage but have a short cooldown and long ranged, its good to combo this with your holy relic ex.
- Lv 1 Crusader's Zeal : only useful in PvE, i think. it will not give much bonus in pvp.
- Holy RELIC EX : ITS A MUST :) I LOVE THOSE GIANT RELICS.
- Half Turn Kick : Action speed
- Electric Smite : Damage
- Armor Break : Damage
- Holy Relic : Damage
- Holy Kick : Action speed
Ok thats all i hope you guys get something useful from this post, thank you :D
PROGRAM PASCAL TEKNIK INSERTION
Berikut ini adalah program implementasi teknik Insertion Sorting menggunakan program Turbo Pascal :
program Insertion;
uses crt;
var input : array [1..10] of integer;
banding,tukar,jumlah,i,j,k,l,m,temp:integer;
begin
clrscr;
writeln('PROGRAM TEKNIK INSERTION');
write('Masukkan jumlah data , maksimal 10 : ');readln(jumlah);
for i := 1 to jumlah do
begin
write('Masukkan data ke -',i,' : ');readln(input[i]);
end;
for j:= 2 to jumlah do
begin
l := j;
m := j-1;
for k:= j-1 downto 1 do
begin
if input[l] < input[m] then
begin
temp := input[l];
input[l] := input[m];
input[m] := temp;
tukar := tukar+1;
end;
if m > 1 then
begin
l := l-1;
m := m-1;
banding := banding+1;
end;
end;
end;
for i:= 1 to jumlah do
begin
write('Data ke -',i,' yang sudah di sortir : ');writeln(input[i]);
end;
write('Jumlah perbandingan : ');writeln(banding);
write('Jumlah pertukaran : ');writeln(tukar);
readln;
end.
program Insertion;
uses crt;
var input : array [1..10] of integer;
banding,tukar,jumlah,i,j,k,l,m,temp:integer;
begin
clrscr;
writeln('PROGRAM TEKNIK INSERTION');
write('Masukkan jumlah data , maksimal 10 : ');readln(jumlah);
for i := 1 to jumlah do
begin
write('Masukkan data ke -',i,' : ');readln(input[i]);
end;
for j:= 2 to jumlah do
begin
l := j;
m := j-1;
for k:= j-1 downto 1 do
begin
if input[l] < input[m] then
begin
temp := input[l];
input[l] := input[m];
input[m] := temp;
tukar := tukar+1;
end;
if m > 1 then
begin
l := l-1;
m := m-1;
banding := banding+1;
end;
end;
end;
for i:= 1 to jumlah do
begin
write('Data ke -',i,' yang sudah di sortir : ');writeln(input[i]);
end;
write('Jumlah perbandingan : ');writeln(banding);
write('Jumlah pertukaran : ');writeln(tukar);
readln;
end.
Tuesday, December 11, 2012
Apa itu Big Oh? sebuah pertanyaan besar
Big
Oh
Big Oh adalah fungsi
yang berkaitan dengan kelajuan proses, dan biasanya digunakan dalam analisis
suatu algoritma untuk menentukan efisiensi dan kompleksitasnya.
-T(n) = O(f(n))
Bila ada suatu konstanta C, maka :
-T(n) ≤ C.(f(n))
Contoh Lain :
·
Jika
f(n) = 5n2 maka T(n) = O(n2)
·
Jika
f(n) = 7n2 + 3n + 5 maka T(n) = O(n2)
·
Jika f(n) = n3 – 2n + 8 maka
T(n) = O(n3)
Klasifikasi
Algoritma berdasarkan notasi Big Oh :
1.
T(n)
= c
Disebut sebagai algoritma konstan,
dimana programnya hanya dieksekusi dengan suatu nilai yang konstan. Bersifat
konstan dan tidak dipengaruhi parameter atau banyak ada yang dieksekusi.
Merupakan algoritma yang paling ideal.
Contoh Program Pascal :
Begin
A:=7;
End.
Maka T(n) = O(1), karena program
hanya dieksekusi satu kali, dan konstan.
2.
T(n)
= O(n)
Disebut algoritma linear, dimana
waktu eksekusinya sebanding dengan jumlah data, dan merupakan kondisi optimal
dalam membuat algoritma.
Contoh Program Pascal :
Begin
For I := 1 to n do
Begin
A:=A+1;
End;
End.
Maka T(n) = O(n) karena program
dieksekusi sejumlah n kali.
3.
T(n)
= O(n2)
Disebut algoritma kuadratik, karena
waktu eksekusi program akan sebanding dengan jumlah kuadrat jumlah data.
Biasanya timbul karena adanya nested loop
atau loop bersarang pada suatu program.
Contoh Program Pascal :
Begin
For I := 1 to n do
Begin
For
J:=1 to n do
Begin
A:=A+1;
End;
End;
End.
Loop dalam di eksekusi n kali. Loop
luar di eksekusi n kali. Oleh karena itu T(n) = O(n2) dan program di
eksekusi n x n atau n2.
4.
T(n)
= O(log n)
Disebut algoritma logaritmik,
karena waktu eksekusi sebanding dengan logaritma dari jumlah data. Biasanya
algoritma ini digunakan untuk memecahkan masalah besar menjadi masalah yang
lebih kecil.
Contoh : algoritma Binary Search
dan algoritma fungsi rekursif.
5.
T(n)
= O(n log n)
Disebut algoritma linearitmik,
karena merupakan gabungan dari linear dan logaritmik, biasanya digunakan untuk
memecahkan masalah yang besar menjadi masalah yang lebih kecil dan diselesaikan
secara terpisah, lalu kemudian hasilnya digabungkan.
Contoh : algoritma Quick Sort.
6.
T(n)
= O(n3)
Merupakan algoritma yang buruk dan
sebisa mungkin dihindari, biasanya algoritma ini dihasilkan dari 3 buah nested loop atau 3 buah loop bersarang.
Contoh program Pascal :
Begin
For I := 1 to n do
Begin
For
J:=1 to n do
Begin
For K:= 1 to n do
Begin
A:=A+1;
End;
End;
End;
End.
Loop terdalam di eksekusi n kali.
Loop tengah di eksekusi n kali. Loop luar di eksekusi n kali. Oleh karena itu
T(n) = O(n3) dan program di eksekusi n x n x n atau n3.
Program Pascal Binary Search
program binary_search;
uses crt;
var input:Array [1..30,1..3] of integer;
jumlah,i,j,cari,langkah:integer;
isi:boolean;
procedure mencari;
function cektengah(var z:integer):integer;
var x:integer;
ada: boolean;
begin
x := 1;
ada := false;
while not(ada) do
begin
if (z = input[x,2]) then
begin
cektengah := x;
ada := true;
end
else
x := x+1;
end;
end;
function cekkirkan(var z:integer): integer;
var x:integer;
ada: boolean;
begin
x := 1;
ada := false;
while not(ada) do
begin
if (z = input[x,1]) or (z =input[x,3]) then
begin
cekkirkan := x;
ada := true;
end
else
x := x+1;
end;
end;
begin
j := cektengah(cari); langkah := 1;
while (j > 1) do
begin
i := input[j,2]; j := cekkirkan(i);
if (input[j,1] = i) or (input[j,3] = i) then
begin
langkah := langkah + 1;
end;
end;
writeln('Angka ditemukan dalam ',langkah,' langkah');
end;
procedure masuk;
function cektengah(var z:integer):integer;
var x:integer;
ada: boolean;
begin
x := 1;
ada := false;
while not(ada) do
begin
if (z = input[x,2]) then
begin
cektengah := x;
ada := true;
end
else
x := x+1;
end;
end;
begin
j:=1;isi:=false;
while not(isi) do
begin
if (input[i,2]>input[j,2])then
begin
if (input[j,3]=0)then
begin
input[j,3]:=input[i,2];
isi:=true;
end
else j:=cektengah(input[j,3]);
end
else
begin
if (input[j,1]=0) then
begin
input[j,1]:=input[i,2];
isi:=true;
end
else j:=cektengah(input[j,1]);
end;
end;
end;
begin
clrscr;
writeln('***************************');
writeln(' Program Binary Search ');
writeln('***************************');
writeln('*****PROGRAM DIMULAI*******');
write('Masukan jumlah input : ');readln(jumlah);
for i:= 1 to jumlah do
begin
write('Masukkan elemen ke -',i,' : ');readln(input[i,2]);
input[i,1]:=0;input[i,3]:=0;
end;
for i:= 2 to jumlah do
begin
masuk;
end;
writeln('****************************');
write('Masukan angka yang dicari : ');readln(cari);
mencari;
writeln('***********************************');
writeln('Terima kasih atas partisipasi anda!');
writeln('*********PROGRAM SELESAI***********');
readln;
end.
uses crt;
var input:Array [1..30,1..3] of integer;
jumlah,i,j,cari,langkah:integer;
isi:boolean;
procedure mencari;
function cektengah(var z:integer):integer;
var x:integer;
ada: boolean;
begin
x := 1;
ada := false;
while not(ada) do
begin
if (z = input[x,2]) then
begin
cektengah := x;
ada := true;
end
else
x := x+1;
end;
end;
function cekkirkan(var z:integer): integer;
var x:integer;
ada: boolean;
begin
x := 1;
ada := false;
while not(ada) do
begin
if (z = input[x,1]) or (z =input[x,3]) then
begin
cekkirkan := x;
ada := true;
end
else
x := x+1;
end;
end;
begin
j := cektengah(cari); langkah := 1;
while (j > 1) do
begin
i := input[j,2]; j := cekkirkan(i);
if (input[j,1] = i) or (input[j,3] = i) then
begin
langkah := langkah + 1;
end;
end;
writeln('Angka ditemukan dalam ',langkah,' langkah');
end;
procedure masuk;
function cektengah(var z:integer):integer;
var x:integer;
ada: boolean;
begin
x := 1;
ada := false;
while not(ada) do
begin
if (z = input[x,2]) then
begin
cektengah := x;
ada := true;
end
else
x := x+1;
end;
end;
begin
j:=1;isi:=false;
while not(isi) do
begin
if (input[i,2]>input[j,2])then
begin
if (input[j,3]=0)then
begin
input[j,3]:=input[i,2];
isi:=true;
end
else j:=cektengah(input[j,3]);
end
else
begin
if (input[j,1]=0) then
begin
input[j,1]:=input[i,2];
isi:=true;
end
else j:=cektengah(input[j,1]);
end;
end;
end;
begin
clrscr;
writeln('***************************');
writeln(' Program Binary Search ');
writeln('***************************');
writeln('*****PROGRAM DIMULAI*******');
write('Masukan jumlah input : ');readln(jumlah);
for i:= 1 to jumlah do
begin
write('Masukkan elemen ke -',i,' : ');readln(input[i,2]);
input[i,1]:=0;input[i,3]:=0;
end;
for i:= 2 to jumlah do
begin
masuk;
end;
writeln('****************************');
write('Masukan angka yang dicari : ');readln(cari);
mencari;
writeln('***********************************');
writeln('Terima kasih atas partisipasi anda!');
writeln('*********PROGRAM SELESAI***********');
readln;
end.
Monday, December 10, 2012
Tugas Pascal Moving Text
Program berikut ini akan membuat tulisan berjalan ke samping lalu ke bawah :
uses crt;
var
a,b:string;
i,j:integer;
x,y:byte;
begin
j:=45;
clrscr;
a:='HELLO WORLD';
for i:=length(a) downto 1 do
begin
j:=j-1;x:=1;y:=1;
b:=copy(a,i,1);
repeat
delay(20);
gotoxy(x,y);write(b);
gotoxy(x-1,y);write(' ');
x:=x+1;
until x>j;
end;
x:=44;
for i:=length(a) downto 1 do
begin
for y:=1 to 20 do
begin
gotoxy(x,y);write(A[i]);
gotoxy(x,y-1);write(' ');
delay(20);
end;
x:=x-1;
delay(50);
end;
readln;
end.
uses crt;
var
a,b:string;
i,j:integer;
x,y:byte;
begin
j:=45;
clrscr;
a:='HELLO WORLD';
for i:=length(a) downto 1 do
begin
j:=j-1;x:=1;y:=1;
b:=copy(a,i,1);
repeat
delay(20);
gotoxy(x,y);write(b);
gotoxy(x-1,y);write(' ');
x:=x+1;
until x>j;
end;
x:=44;
for i:=length(a) downto 1 do
begin
for y:=1 to 20 do
begin
gotoxy(x,y);write(A[i]);
gotoxy(x,y-1);write(' ');
delay(20);
end;
x:=x-1;
delay(50);
end;
readln;
end.
Sunday, December 9, 2012
Program Pascal STACK
program infix_postfix;
uses crt;
type s100 = string[100];
stacks = record
stack : s100;
top : 0..100
end;
var infix, postfix : s100;
operator : set of char ;
x,y:byte;
i:integer;
procedure push (var s : stacks; elements : char);
begin
s.top := s.top + 1;
s.stack[s.top] := elements
end;
function pop (var s : stacks) : char;
begin
pop := s.stack[s.top];
s.top := s.top - 1;
end;
function priority (tanda : char) : integer;
begin
case tanda of
'^' : priority := 3;
'*', '/' : priority := 2;
'+', '-' : priority := 1;
'(' : priority := 0
end
end;
procedure convert (infix : s100);
var i : integer;
test : boolean;
temp, kar : char;
s : stacks;
begin
postfix:='';
for i := 1 to length(infix) do
begin
kar := infix[i];
if kar = '(' then push(s, kar)
else if kar = ')' then
begin
while s.stack[s.top] <> '(' do
postfix:=postfix + pop(s);
temp := pop(s)
end
else if kar in operator then
begin
while (s.top <> 0) and (priority(kar) <= priority(s.stack[s.top])) do
postfix:=postfix + pop(s);
push(s, kar)
end
else if kar <> ' ' then postfix:=postfix + kar;
end;
if s.top <> 0 then
repeat
postfix:=postfix + pop(s)
until s.top = 0;
end;
procedure animate(postfix:string);
begin
x:=13;
for i:=1 to length(postfix) do
begin
for y:=7 to 14 do
begin
gotoxy(x,y);write(postfix[i]);
gotoxy(x,y-1);write(' ');
delay(20);
end;
x:=x+1;
delay(50);
end;
end;
begin
clrscr;
operator:= ['^','*','/','+','-'];
writeln('===================================');
writeln('| mengubah infix menjadi postfix |');
writeln('===================================');
gotoxy (5,7);
write('infix = ');
readln(infix);
gotoxy (5,14) ;
write('hasil = ');
convert (infix);
animate(postfix);
gotoxy(13,7); write(infix);
gotoxy (5,16);
writeln('terimakasih atas partisipasi anda');
readln;
end.
uses crt;
type s100 = string[100];
stacks = record
stack : s100;
top : 0..100
end;
var infix, postfix : s100;
operator : set of char ;
x,y:byte;
i:integer;
procedure push (var s : stacks; elements : char);
begin
s.top := s.top + 1;
s.stack[s.top] := elements
end;
function pop (var s : stacks) : char;
begin
pop := s.stack[s.top];
s.top := s.top - 1;
end;
function priority (tanda : char) : integer;
begin
case tanda of
'^' : priority := 3;
'*', '/' : priority := 2;
'+', '-' : priority := 1;
'(' : priority := 0
end
end;
procedure convert (infix : s100);
var i : integer;
test : boolean;
temp, kar : char;
s : stacks;
begin
postfix:='';
for i := 1 to length(infix) do
begin
kar := infix[i];
if kar = '(' then push(s, kar)
else if kar = ')' then
begin
while s.stack[s.top] <> '(' do
postfix:=postfix + pop(s);
temp := pop(s)
end
else if kar in operator then
begin
while (s.top <> 0) and (priority(kar) <= priority(s.stack[s.top])) do
postfix:=postfix + pop(s);
push(s, kar)
end
else if kar <> ' ' then postfix:=postfix + kar;
end;
if s.top <> 0 then
repeat
postfix:=postfix + pop(s)
until s.top = 0;
end;
procedure animate(postfix:string);
begin
x:=13;
for i:=1 to length(postfix) do
begin
for y:=7 to 14 do
begin
gotoxy(x,y);write(postfix[i]);
gotoxy(x,y-1);write(' ');
delay(20);
end;
x:=x+1;
delay(50);
end;
end;
begin
clrscr;
operator:= ['^','*','/','+','-'];
writeln('===================================');
writeln('| mengubah infix menjadi postfix |');
writeln('===================================');
gotoxy (5,7);
write('infix = ');
readln(infix);
gotoxy (5,14) ;
write('hasil = ');
convert (infix);
animate(postfix);
gotoxy(13,7); write(infix);
gotoxy (5,16);
writeln('terimakasih atas partisipasi anda');
readln;
end.
Saturday, November 24, 2012
Operasi pengurangan pada bilangan Biner
Operasi
pengurangan pada bilangan Biner
Pada operasi pengurangan bilangan Biner dikenal 2 cara
untuk menyelesaikan permasalahan tersebut, yang pertama kita kenal dengan nama Komplemen Satu dan yang kedua kita
kenal dengan Komplemen Dua.
Komplemen pada umumnya adalah proses penggantian 1 dengan
0 atau sebaliknya 0 dengan 1.
Komplemen Satu dan Komplemen Dua hanya berbeda pada waktu
penjumlahan hasil komplemen dengan 1(satu). Pada Komplemen Satu, hasil jumlah kedua
bilangan yang akan ditambahkan dengan bilangan 1, sementara pada Komplemen Dua,
hasil komplemen bilangan negatif lah yang akan dijumlahkan dengan 1 baru
kemudian kedua bilangan dijumlahkan. Untuk lebih jelasnya mari kita simak
contoh berikut :
Contoh
(1):
Kasus
8+(-7) dengan cara Komplemen Satu
8 = 0000
1000
-7 = 1111
1000 (dimana -7 kita dapat dari 7 yang di komplemen)
----------- +
=
0000 0000
= 0000
0001 (ditambahkan dengan 1)
-----------
+
1 = 0000
0001 (dimana hasil dari 8+(-7) adalah 1)
Kasus
8+(-7) dengan Komplemen Dua
Untuk Komplemen Dua, terlebih dahulu kita menambahkan (-7)
dengan 1 , setelah itu baru kita jumlahkan dengan 8.
-7 = 1111
1000
= 0000
0001 (ditambahkan dengan 1)
------------
+
-7 = 1111 1001
Maka,
8 = 0000
1000
-7 = 1111
1001
------------
+
1 = 0000
0001 (dimana hasil dari 8+(-7) adalah 1)
Contoh
(2):
Kasus
8+(-10) dengan cara Komplemen Satu
8 = 0000
1000
-10 = 1111
0101 (dimana -10 kita dapat dari 10 yang di komplemen)
----------- +
=
1111 1101
=
0000 0001 (ditambahkan dengan 1)
-----------
+
-2 = 1111
1110 (dimana hasil dari 8+(-10) adalah -2)
Kasus
8+(-10) dengan Komplemen Dua
Untuk Komplemen Dua, terlebih dahulu kita menambahkan
(-10) dengan 1 , setelah itu baru kita jumlahkan dengan 8.
-10 = 1111
0101
=
0000 0001 (ditambahkan dengan 1)
------------
+
-10 = 1111
0110
Maka,
8 = 0000
1000
-10 = 1111
0110
------------
+
-2 = 1111
1110 (dimana hasil dari 8+(-10) adalah -2)
Subscribe to:
Posts (Atom)