You are on page 1of 14

A.

ADT QUEUE

1. procedure createEmpty(output Q : Queue)


Kamus :
Algoritma :
Q.head?NULL;
Q.tail?NULL;

2. function alokasi(nimX : integer; namaX : string; int nilaiX : integer)?address


kamus :
p : address
Algoritma
P?(address)malloc(sizeof(m1));
if(p<>NULL) then
p^,nim?nimX;
p^.nama?namaX;
p^.nilai?nilaiX;
p^.next?NULL;
endif
return p;

3. procedure dealokasi(input p :address )


kamus :
algoritma :
free(p);

4. function isEmpty(input Q : Queue)?boolean


if(Q.head==NULL) then
? true;
else
? false;
Endif

5. procedure addAddress(input/output Q : Queue , input p : address )


kamus
algoritma
if(isEmpty(Q)) then
(Q).head?p;
(Q).tail?p;
else
(Q.tail)^.next?p;
(Q).tail?p;
Endif

6. procedure add(input/output Q : Queue , input nimX : integer; input namaX: string;


input nilaiX : integer)

Kamus :
q : address
Algoritma :
q ? alokasi(nimX,namaX,nilaiX);
addAddress(Q,q);

7. procedure del(input/output Q : Queue; output nimX : integer; output namaX :


integer; output nilaiX: integer)
kamus :
q : address
algoritma :
nimX ? ((Q).head)^.nim;
strcpy(namaX,((Q).head)^.nama);
nilaiX ? ((Q).head)^.nilai;
q ? (Q).head;
(Q).head ? ((Q).head)^.next;
dealokasi(q);

B. INFIXTOPOSTFIX DAN MAINPROGRAM


char pop() { /* fungsi untuk operasi pop */
? (s[top--]);
}

pr: integer( elem:char) { /* Fungsi untuk precedence */


switch (elem) {
depend on '#':
?0;
depend on '(':
?1;
depend on '+':
depend on '-':
?2;
depend on '*':
depend on '/':
?3;
}
}

main() { /* Main Program */


infx[50]:char, pofx[50], ch, elem;

i:integer ?0, k ? 0;
output("\n\nBaca formula Infix ? ");
input("%s", infx);
push('#');
while ((ch ? infx[i++]) != '\0') {
if (ch = '(')
push(ch);
else if (isalnum(ch))
pofx[k++] = ch;
else if (ch = ')') {
while (s[top] != '(')
pofx[k++] ? pop();
elem ? pop(); /* Buang ( */
} else { /* Operator */
while (pr(s[top]) >= pr(ch))
pofx[k++] ? pop();
push(ch);
}
}
while (s[top] <> '#') /* Pop from stack sampai kosong */
pofx[k++] ? pop();
pofx[k] ? '\0'; /* buat pofx sebagai valid string */
output("\n\nGiven Infix Expn: %s Postfix Expn: %s\n", infx, pofx);
}

C. PROGRAM BASIS DAN CONVERT


#include <stdio.h>
#include <string.h>

1. procedure welcome() {
output("Selamat datang di Basis Angka Konverter");
output("\nby Astiya, Dinda, Yunita)");
}

2. procedure cls() {
i:integer;
for (i? 0;i<100;i++) {
ouput("\n");
}
}

3. procedure biner(n:integer) {
if (n > 0) {
biner(n/2);
output("%d",n%2);
}

4. fungsi pangkat( n, x:integer) {


nilai:integer? 1,i;
for (i? 0;i<x;i++) {
nilai? nilai*n;
}
? nilai;
}

5. fungsi cekdesimal( x:integer) {


//checking
if (x < 0) { //no minus
? 1;
}
//end of checking, all is right
? 0;
}

6. fungsi cekbiner(str[]:char, *x:integer) {


i:integer,dec ? 0;
//checking
for (i ? 0; i < strlen(str); i++)
{
if ((str[i] - '0' <> 1 ) and (str[i] - '0' <> 0))
{
? 1;
}
}
//end of checking, all is right

for (i ? 0; i < strlen(str) ; i++)


{
if (str[i] - '0' = 1) {
dec ? dec + pangkat(2,strlen(str)-1-i);
}
}
*x ? dec;
? 0;

7. fungsi cekoktal(str[]:char, *x:integer) {


i:integer,dec? 0;
//checking
if ((strlen(str) >= 6) and (str[0] > 49)) {
? 1;
}
for (i ? 0; i < strlen(str); i++)
{
if (not((str[i] > 47 ) and (str[i] < 56)))
{
? 1;
}
}
//end of checking, all is right
for (i ? 0; i < strlen(str) ; i++)
{
dec ? dec + (str[i] - '0') * pangkat(8,strlen(str)-1-i);
}
*x ? dec;
? 0;
}

8. fungsi cekhexa(str[]:char, *x:integer) {


i:integer,dec? 0;
//checking
for (i ? 0; i < strlen(str); i++)
{
if (not ( ((str[i] > 47 ) (str[i] < 58)) || ((str[i] > 96 ) and (str[i] < 103)) || ((str[i] >
64 ) and (str[i] < 71)) ))
{
? 1;
}
}
//end of checking, all is right
for (i ? 0; i < strlen(str) ; i++)
{
if ((str[i] >= '0' ) and (str[i] <= '9')) {
dec ? dec + (str[i] - '0') * pangkat(16,strlen(str)-1-i);
}
else if ((str[i] > '@' ) and (str[i] < 'G')) {
dec ? dec + (str[i] - 55) * pangkat(16,strlen(str)-1-i);
}
else if ((str[i] > 96 ) and (str[i] < 'g')) {
dec ? dec + (str[i] - 87) * pangkat(16,strlen(str)-1-i);
}
}
*x ? dec;
? 0;
}

D. MAIN PROGRAM
int main(){
output("
output("
\n");

\n");

APLIKASI BASIS

\n");

output(" ___________________________________________________\n");
output("
\n");
output("
Astiya Putri
(1107134154)
output("
Dinda Murni
(1107130073)
\n");
output("
Yunita Ayu Lestari
(1107130069)
output("
\n");
output("
Pemrograman Terstruktur II, IK-37-03

output("
S1 Ilmu Komputasi
output(" __________________________________________________ \n");
output(" press any key to continue \n");
getch();
system("cls");

\n");
\n");

\n");

x:integer,dec;
oct[6],bin[16],hex[4]:char;
welcome();
while(1) {
output("\n\n===============================\nBasis Angka
Masukan\n1. Desimal\n2. Biner\n3.
Oktal\n4. Heksadesimal \n5. Keluar \nMasukan
pilihan anda: ");
input(x);
switch(x) {

depend on 1:
output("Masukan angka desimal (Maksimal 65535): ");
input("%d",&dec);
if(cekdesimal(dec) != 0) {
printf("Input salah");
break;
}
output("Biner: ");
biner(dec);
output("\nOktal: %o",dec);
output("\nHexa: %X",dec);
break;
depend on 2:
output("Masukan angka biner (Maksimal 16 bit): ");
input("%s",bin);
if(cekbiner(bin,&dec) != 0) {
output("Input salah");
break;
}
output("\nDesimal: %d",dec);
output("\nOktal: %o",dec);
output("\nHexa: %X",dec);
break;
depend on 3:
output("Masukan angka Oktal (Maksimal 177777): ");
input("%s",oct);
if(cekoktal(oct,&dec) != 0) {
output("Input salah");
break;
}
output("Desimal: %d",dec);
output("\nBiner: ");
biner(dec);
output("\nHexa: %X",dec);
break;
depend on 4:
output("Masukan angka hexa (Maksimal FFFF): ");
input("%s",hex);
if(cekhexa(hex,&dec) != 0) {
output("Input salah");
break;
}
output("Desimal: %d",dec);
output("\nBiner: ");
biner(dec);
output("\nOktal: %o",dec);
break;
}

default:

} //end case
} //end loop
? 0;
} //end main

output("Not Present");

E. program_konversi dan evaluasi postfix


#define SIZE 50
/* ukuran Stack */
#include <ctype.h>
char s[SIZE];
top:integer ? -1; /* kamus global */
push(char elem) { /* fungsi */
s[++top] ? elem;

You might also like