#include<stdio.h>
int const maxstk=9;
int push(int stack[], int top, int maxstk, int item)
{
if(top==maxstk)
{
printf("\nOVERFLOW");
return 0;
}
stack[top]=item;
top=top+1;
printf("\nPUSH performed");
printf("\nStack is ");
for(int i=0;i<top;i++)
printf("%d ",stack[i]);
return 0;
}
int pop(int stack[10],int top,int item)
{
if(top == 0)
{
printf("\nUNDERFLOW");
return 0;
}
item=stack[top];
top=top-1;
printf("\nPOP performed");
printf("\nStack is ");
for(int i=0;i<top;i++)
printf("%d ",stack[i]);
return 0;
}
void main()
{
int i,stack[10],item,x,top=5;
printf("\nEnter stack elements ");
for( i=0;i<5;i++)
scanf("%d",&stack[i]);
printf("\nStack is ");
for( i=0;i<top;i++)
printf("%d ",stack[i]);
printf("\nEnter \t 1- to enter element(PUSH)\n \t 2- to delete element(POP)\n \t ");
scanf("%d",&x);
if(x==1)
{
printf("\nEnter the element you want to push into stack ");
scanf("%d",&item);
push(stack,top,maxstk,item);
}
else if(x==2)
{
pop(stack,top,item);
}
}
for more codes you can visit http://codesofprogramming.blogspot.in/
int const maxstk=9;
int push(int stack[], int top, int maxstk, int item)
{
if(top==maxstk)
{
printf("\nOVERFLOW");
return 0;
}
stack[top]=item;
top=top+1;
printf("\nPUSH performed");
printf("\nStack is ");
for(int i=0;i<top;i++)
printf("%d ",stack[i]);
return 0;
}
int pop(int stack[10],int top,int item)
{
if(top == 0)
{
printf("\nUNDERFLOW");
return 0;
}
item=stack[top];
top=top-1;
printf("\nPOP performed");
printf("\nStack is ");
for(int i=0;i<top;i++)
printf("%d ",stack[i]);
return 0;
}
void main()
{
int i,stack[10],item,x,top=5;
printf("\nEnter stack elements ");
for( i=0;i<5;i++)
scanf("%d",&stack[i]);
printf("\nStack is ");
for( i=0;i<top;i++)
printf("%d ",stack[i]);
printf("\nEnter \t 1- to enter element(PUSH)\n \t 2- to delete element(POP)\n \t ");
scanf("%d",&x);
if(x==1)
{
printf("\nEnter the element you want to push into stack ");
scanf("%d",&item);
push(stack,top,maxstk,item);
}
else if(x==2)
{
pop(stack,top,item);
}
}
for more codes you can visit http://codesofprogramming.blogspot.in/
No comments:
Post a Comment