stack using struct 1,c
stack using struct 1,c
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
struct stack
{
int stck;
}
struct stack s[100];
int i,j,n,top=-1;
void push()
{
if(top==n)
printf("\noverflow");
else
{
top++;
printf("\nenter element :");
scanf("%d",&s[top].stck);
}
}
void pop()
{
if(top==-1)
printf("\nunderflow");
else
{
printf("\nPopped element : %d",s[top--].stck);
}
}
void traverse()
{
printf("\n");
for(i=0;i<top;i++)
{
printf("%d\t",s[i].stck);
}
}
int main()
{
printf("enter size of stack :");
scanf("%d",&n);
while(1)
{
// system("cls");
printf("\nenter \n1->push\t2->pop\t3->display\t4->end");
scanf("%d",&j);
switch(j)
{
case 1:
{
push();break;
}
case 2:
{
pop(); getch(); break;
}
case 3:
{
traverse();getch();break;
}
case 4: exit(0);