NIM : 201101004
Program STACK Nang Borlan
#include<iostream.h>
#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<<" === Program Stack === \n";
cout<<" 1. Push \n ";
cout<<"2. Pop \n ";
cout<<"3. Print \n ";
cout<<"4. Clear \n ";
cout<<"5. Exit \n ";
cout<<"===================== \n";
cout<<" Pilihan : ";
cin>>pil;
switch(pil)
{
case 1:
if(IsFull() !=1){
cout<<" Data = ";
cin>>dt;
Push(dt);
}
else cout<<" \n Stack Sampun penuh ! \n ";
break;
case 2:
if(IsEmpty() !=1){
Pop();
}else
cout<<"\n Stack Wis Kosong ! \n ";
break;
case 3:
if(IsEmpty() !=1){
TampilStack();
}else
cout<<"\n Stack Uwis Kosong ! \n ";
break;
case 4:
Clear();
cout<<"\n Stack Sampun Kosong ! \n ";
break;
}
getche();
}
while(pil !=5);
getche();
}
Output Program Borlane
Program STACK Ning Eclipse
//=================================================
// Name : 1.cpp
// Author : Gatra Mustakim
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//=================================================
#include<iostream>
#include<cstring>
#define MAX_STACK 10
using namespace std;
#include<conio.h>
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--;
cout<<endl;
}
void TampilStack()
{
for(int i = tumpuk.top;i>=0;i--)
{
cout<<" Data : "<<tumpuk.data[i];
cout<<endl;
}
}
void Clear()
{
tumpuk.top=-1;
}
int main()
{
int pil;
inisialisasi();
char dt[10];
do {
cout<<" =====Program STACK==== \n";
cout<<" 1. Push \n ";
cout<<"2. Pop \n ";
cout<<"3. Print \n ";
cout<<"4. Clear \n ";
cout<<"5. Exit \n ";
cout<<" ====================== \n";
cout<<" Pilihan : ";
cin>>pil;
switch(pil)
{
case 1:
if(IsFull() !=1){
cout<<" Data = ";
cin>>dt;
Push(dt);
}
else cout<<" \n Stack penuh ! \n ";
break;
case 2:
if(IsEmpty() !=1)
Pop();
else
cout<<"\n Stack Kosong ! \n ";
break;
case 3:
if(IsEmpty() !=1)
TampilStack();
else
cout<<"\n Stack Kosong ! \n ";
break;
case 4:
Clear();
cout<<"\n Stack Sudah Kosong ! \n ";
break;
}
//getche();
}
while(pil !=5);
return 0;
}
Tidak ada komentar:
Posting Komentar