Implementation of push n pop
//Implementation of push n pop in stack . You can take this for pushing and poping //out some element from the top of the stack.
#include
#include
int s[10],top=0,x;
void push(int x);
int pop();
void prtstk();
int size();
int main()
{
int c;
clrscr();
for( ; ; )
{
printf("1. push\n");
printf("2. pop\n");
printf("3. print all elements\n");
printf("4. size\n");
printf("5. quit\n");
printf("enter your choice:");
scanf("%d",&c);
switch(c)
{
case 1:
printf("enter the element\n");
scanf("%d",&x);
push(x);
break;
case 2:
c=pop();
printf(" poped element is:%d\n",c);
break;
case 3:
prtstk();
break;
case 4:
c=size();
printf("size = %d\n",c);
getch();
break;
case 5:
exit(0);
}
}
}
void push(int x)
{
if(top<10)
{
top++;
s[top]=x;
}
else
printf("stack is full\n");
}
int pop()
{
if(top==0)
{
printf("stack is empty\n");
return 0;
}
else
{
return(s[top--]);
}
}
int size()
{
return(top);
}
void prtstk()
{
int i;
for (i=1;i<=top;i++)
printf("%d\n",s[i]);
}

0 comments:
Post a Comment