#include
#define MAX 5
#define true 1
#define false 0
using namespace std;
char stack[MAX];
int top;
void init(void);
int full(void);
int empty(void);
char pop(void);
void clear(void);
void push(char info);
void baca(void);
int main()
{
char pilih,elm;
cout<<"demo operasi single stack"<
do
{
cout<<"OPERASI SINGLE STACK :"<
switch(pilih)
{
case '1':cout<<"PUSH-->";cin>>elm;
push(elm);
break;
case '2':elm=pop();
cout<<"pop"<
case '3':clear();
break;
case '4':baca();
break;
case '5':break;
default:cout<<"salah pilih..."<
cout<
while(pilih!='5');
}
void init(void)
{
top=0;
}
void push(char info)
{
if(full()!=true)
{
top++;
stack[top]=info;
}
else
cout<<"stack overflow..."<
char pop(void)
{
char info;
if(empty()!=true)
{
info=stack[top];
top--;
return(info);
}
else
cout<<"stack underflow..."<
void clear(void)
{
top=0;
}
int full(void)
{
if(top==MAX)
return(true);
else
return(false);
}
int empty(void)
{
if(top==0)
return(true);
else
return(false);
}
void baca(void)
{ int i;
cout<<"isi stack:"<
if(top>0)
{
for(i=1;i<=top;i++)
cout<
else
cout<<"(kosong)";
cout<
0 comments:
Post a Comment