#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#define MAXSIZE 4
int stack[MAXSIZE];
int top;
void main()
{
void push(int);
int pop();
int i,num;
int pill= 0;
while (pill == 0)
{
printf("\n +=== MAIN MENU ====+");
printf("\n +==================+");
printf("\n | 1. Push Stack |");
printf("\n | 2. Pop Stack |");
printf("\n | 3. Keluar |");
printf("\n +==================+\n");
printf("\n pilihan : ");
scanf("%d",&pill);
switch(pill)
{
case 1:
printf(" Push elemen stack : ");
scanf("%d",&num);
push(num);
break;
case 2:
i=pop();
printf(" Pop elemen stack %d ",i);
break;
case 3:
exit(0);
break;
default: printf("\n Maaf pilihan tersebut tidak tersedia !!");
}
printf("\n\n Apakah anda ingin keluar [1/0] ? ");
scanf("%d" , &pill);
}
}
void push(int y)
{
if(top>MAXSIZE)
{
printf("\n STACK telah terisi penuh !! ");
return;
}
else
{
top++;
stack[top]=y;
}
}
int pop()
{
int a;
if(top<=0)
{
printf("\n STACK kosong !! ");
return 0;
}
else
{
a=stack[top];
top--;
}
return(a);
}
Like this:
Like Loading...
Related