Stack Operation (push, pop & status)
















//Stack operation(If u choice :1 that time operation will be popped,if u choice :2 that time operation will be pushed ,if u choice:3  that time operation will be showed stack status )

---------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------
#include<stdio.h>
int main()
{
int i,stack[9],top,element,n=10,c;
float free;
printf("Enter the top number value:\n");
scanf("%d",&top);
printf("Enter the stack element :\n");
for(i=0;i<=top;i++)
{
scanf("%d",&stack[i]);
}
x :printf("***********STACK OPERATION************\n");
printf("1=> for pop .\n2=>for push.\n3=> for Status.\n");
printf("*Enter your choice:\n");
scanf("%d",&c);
while(c>3||c<1)
{
printf("Please Enter the proper choice:\n");
scanf("%d",&c);
}
switch(c)
{
case 1:
if(top<0)
{
printf("The stack is empty .\n No need to delete.");
}
else
{
element=stack[top];
top=top-1;
printf("The pop operation is:\n");
for(i=0;i<=top;i++)
{
printf("%d\n",stack[i]);
}
}

break;
case 2:
if(top>=n)
{
printf("The stack is full.\n So we can not enter any data\n");
}
else
{
printf(" Enter the inserted element :\n");
scanf("%d",&element);
top=top+1;
stack[top]=element;
printf("The push operation is\n");
for(i=0;i<=top;i++)
{
printf("%d\n",stack[i]);
}
}
break;
case 3:

free=(float)((n-top)*100)/n;
if(free<=0)
{
printf("Free persentage is less than zero.\n");
}
else
printf("The total free stack is:%2f",free,"percentage\n");
}

goto x;
}

(By:shahimtiyaj)

SHARE

Shah Imtiyaj

Try to know thyself

  • Image
  • Image
  • Image
  • Image
  • Image
    Blogger Comment
    Facebook Comment

0 comments:

একটি মন্তব্য পোস্ট করুন