0% found this document useful (0 votes)
5 views2 pages

Stack Using Array

Uploaded by

apexop4480
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

Stack Using Array

Uploaded by

apexop4480
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

/**********STACK IMPLEMENTATION USING ARRAY**********/

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#define MAX 5
int top=-1;
int st[MAX];
void main()
{
int x,ch;
void push (int);
int pop();
void show();
clrscr();
while(1)
{
printf("\n1.Push");
printf("\n2.Pop");
printf("\n3.Display");
printf("\nExit");
printf("\nEnter your choice::");
scanf("%d",&ch);
switch(ch)
{
case 1:
if(top>=MAX-1)
printf ("\nStack is full");
else
{
printf("\Enter number ::");
scanf("%d",&x);
push(x);
}
break;
case 2:
if(top==-1)
printf("\nStack is empty");
else
printf("\nThe poped item=%d",pop());
break;
case 3:
show();
break;
case 4:
exit(0);
}
}
getch();
}
void push(int x)
{
top++;
st[top]=x;
}
int pop()
{
int x;
x=st[top--];
return x;
}
void show()
{
int i;
if(top>=0)
{
for(i=top;i>=0;i--)
printf("%4d",st[i]);
}
else
printf("\nStack is empty");
}

You might also like