You are on page 1of 3

DATA STRUCTURE AND ALGORITHM

Dorado,Benjie
Gadingan,Jeric

LAST ACTIVITY
#include<stdio.h> int val;
#include <conio.h>
if(top==MAX-1)
#define MAX 8 {
void push(); printf("\nStack is full!!");
void pop(); }
void display(); else
stack[MAX]; {
int top=-1,ch; printf("\nEnter element to
main() push:");
{ scanf("%d",&val);
while(1) top=top+1;
{ stack[top]=val;
printf("\n*** Stack Menu ***"); }
}
printf("\n\n1.Push\n2.Pop\n3.Display
\n4.Exit"); void pop()
printf("\n\nEnter your {
choice(1-4):"); if(top==-1)
scanf("%d",&ch); {
printf("\nStack is empty!!");
switch(ch) }
{ else
case 1: push(); {
break; printf("\nDeleted element is
case 2: pop(); %d",stack[top]);
break; top=top-1;
case 3: display(); }
break; }
case 4: exit(0);
void display()
default: {
printf("\nWrong Choice!!"); int i;
}
} if(top==-1)
} {
printf("\nStack is empty!!");
void push() }
{ else
{
printf("\nStack is...\n");
for(i=top;i>=0;--i)
printf("%d\n",stack[i]);
}
}

You might also like