Implementaion of Stack 2
Implementaion of Stack 2
#include <stdio.h>
#include <conio.h>
#include <process.h>
#include <stdlib.h>
#define MAX_SIZE 10
#define bottom -1
voidinitStack( );
intisFull();
intisEmpty();
void push(int);
void pop();
void peep();
void traverse();
int stack[MAX_SIZE];
int top;
void main()
printf("\n....MENU... \n");
printf("2. Push\n");
printf("3. Pop\n");
printf("4. Peep\n");
printf("5. Traverse\n");
printf("6. Quit\n");
scanf("%d", &choice);
continue;
switch (choice)
case 1:
initStack();
break;
case 2:
scanf("%d", &item);
push(item);
break;
case 3:
pop();
break;
case 4:
peep();
break;
case 5:
traverse();
break;
case 6:
printf("End of program\n");
exit(0);
voidinitStack()
{
top = bottom;
printf("Stack initialized\n");
intisFull()
if(top == MAX_SIZE - 1)
return (1);
else
return (0);
intisEmpty()
if (top == bottom)
return (1);
else
return (0);
void push(intnewitem)
if (isFull())
printf("Stack overflow\n");
else
top =top+1;
stack[top] = newitem;
void pop()
if (isEmpty())
printf("Stack underflow\n");
else
top = top-1;
void peep()
if (isEmpty())
printf("Stack is empty\n");
else
printf("Top of stack= %d\n", stack[top]);
void traverse()
int i;
if(isEmpty())
printf("Stack is empty\n");
else
printf(" %d\n",stack[i]);
} getch();
}
Output=
1. STACK INITILIZED