Recent Post

STACK Program using Array in C

#include<stdio.h>
#include<conio.h>
#define MAXSIZE
void Push();
void Pop();
void display();
int top = -1;
int item,i;
int s[MAXSIZE];
void main()
{
int choice;
clrscr();
do
 {
printf("1.Push\n");
printf("2.Pop\n");
printf("3.display\n");
printf("4.Exit\n");
scantf("%d",&choice);
switch(choice)
{
case 1: Push();
            break;
case 2: Pop();
            break;
case 3: display();
            break;
case 4: exit(0);
default : printf("\n Wrong choice\n");
}
while(choice !=4);
getch();
}
void Push()
{
if(top == MAXSIZE -1)
printf("stack overflow\n");
else
{
printf("Enter nos.\n");
scanf("%d",&item);
top = top + 1;
a[top]=item;
}
}
void Pop()
{
if(top== -1)
{
printf("stack overflow\n");
return;
}
else
{
printf("Deleted element = %d\n",s[top]);
top = top -1;
}
}
void display()
{
if(top ==  -1)
printf("stack is empty\n");
else
{
printf("stack element are \n");
for(i=top;i>=0;i--)
printf("%d\n",s[i]);
}
}

 

No comments