Stack function

Push Operation

In case of stack Insertion of any item in stack is called push. In stack any item is inserted from top of the stack, When you insert any item in stack top will be increased by 1.
Declaration of structure for stack operation 
Global variable declaration   int top=-1, size=5;
struct stack
  {
   int item;
   int stack[size];
  }s;   
void push()
  {
   int item;
  if(top==size-1)
  {
  printf("\n stack is full");
  }
  else
  {
  top=top+1;
  printf("\n\n Enter element in stack: ");
  scanf("%d",&s.item);
  s.stack[top]=s.item;
  }
  }

POP Operation

In case of stack deletion of any item from stack is called pop. In any item is delete from top of the stack, When you delete any item from stack top will be decreased by 1.

void pop()
{
int item;
if(top==0)
{
printf("\nStack is empty: ");
}
else
{
s.item=s.stack[top];
top=top-1;
printf("deleted data is: %d",s.item);
}
}
Display the content of stack
void display()
  {
   int i;
   if(top==0)
   {
   printf("\n Stack is empty: ");
   }
   else
   {
    for(i=top;i>0;i--)
    {
    printf("\n%d",s.stack[i]);
    }
   }
  }

Popular posts from this blog

18CS45 object oriented concept (OOC) notes, question paper

python application program 15CS664 notes question paper , important question

Operation Research Notes 15CS653