Minggu, 17 Juni 2012

LAPORAN PRAKTIKUM STACK (RISKI YOGA KUSUMADYA (201101019))

LAPORAN PRAKTIKUM STACK
Disusn Oleh :
Riski Yoga Kusumadya
201101019

Dosen :
Yosef Murya Kusuma Ardhana, S.T

JURUSAN SISTEM INFORMASI
SEKOLAH TINGGI ILMU KOMPUTER (STIKom)
"YOS SUDARSO"
PURWOKERTO
2012



============================================================================

Listing Program Eclipse dan Borland

ECLIPSE

//============================================================================
// Name        : stack1.cpp
// Author      : 
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;


//#include <iostream>
//#include <conio.h>
#include <string.h>

#define MAX_STACK 10

//int main() {
struct STACK {
int top;
char data[10][10];
};STACK tumpuk;

void inisialisasi()
{
tumpuk.top=-1;
}

int IsFull()
{
if(tumpuk.top==MAX_STACK-1)return 1; else return 0;
}

int IsEmpty()
{
if(tumpuk.top==-1)return 1; else return 0;
}

void Push(char d[10])
{
tumpuk.top++;
strcpy(tumpuk.data[tumpuk.top],d);
}

void Pop(){
cout<<"data yang terambil ="<<tumpuk.data[tumpuk.top];
tumpuk.top--;
}

void TampilStack (){
for(int i=tumpuk.top;i>=0;i--)
{
cout<<"data :"<<tumpuk.data[i]<<endl;
}
}

void Clear()
{
tumpuk.top=-1;
}

int main()
{
int pil;
inisialisasi();
char dt[10];
do{
cout<<"1.push\n";
cout<<"2.pop\n";
cout<<"3.print\n";
cout<<"4.clear\n";
cout<<"5.exit\n";
cout<<"pilihan :\n";
cin>>pil;
cout<<"\n";

switch(pil){
case 1:if(IsFull()!=1){
cout<<"data =";cin>>dt;
Push(dt);
}else cout<<"Stack penuh!\n";
break;

case 2:if(IsEmpty()!=1)
Pop();
else
cout<<"Stack Kosong!\n";
break;

case 3:if(IsEmpty()!=1)
TampilStack();
else cout<<"Stack kosong\n";
break;

case 4:Clear();
cout<<"Satck sudah kosong\n";
break;
}
//getche();
}while(pil!=5);
//getche();
//}
return 0;
}


BORLAND

#include <conio.h>
#include <string.h>

#define MAX_STACK 10

struct STACK {
int top;
char data[10][10];
};STACK tumpuk;

void inisialisasi()
{
tumpuk.top=-1;
}

int IsFull()
{
if(tumpuk.top==MAX_STACK-1)return 1; else return 0;
}

int IsEmpty()
{
if(tumpuk.top==-1)return 1; else return 0;
}

void Push(char d[10])
{
tumpuk.top++;
strcpy(tumpuk.data[tumpuk.top],d);
}

void Pop(){
cout<<"data yang terambil ="<<tumpuk.data[tumpuk.top];
tumpuk.top--;
}

void TampilStack (){
for(int i=tumpuk.top;i>=0;i--){              
cout<<"data :"<<tumpuk.data[i]<<endl;
}
}

void Clear()
{
tumpuk.top=-1;
}

int main()
{
int pil;
inisialisasi();
char dt[10];
do{
cout<<"1.push\n";
cout<<"2.pop\n";
cout<<"3.print\n";
cout<<"4.clear\n";
cout<<"5.exit\n";
cout<<"pilihan :\n";
cin>>pil;
cout<<"\n";

switch(pil){
case 1:if(IsFull()!=1){
cout<<"data =";cin>>dt;
Push(dt);
}else cout<<"Stack penuh!\n";
break;

case 2:if(IsEmpty()!=1)
Pop();
else
cout<<"Stack Kosong!\n";
break;

case 3:if(IsEmpty()!=1)
TampilStack();
else cout<<"Stack kosong\n";
break;

case 4:Clear();
cout<<"Satck sudah kosong\n";
break;
}
getche();
}while(pil!=5);
getche();
}

OUTPUT PROGRAM

ECLIPSE


BORLAND


Tidak ada komentar:

Posting Komentar