Push Operation in C++


Prev Tutorial Next Tutorial

Insert Item in Stack in C++

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.

insert item in stack in c++

Algorithm for push

  • Initialization, set top=-1
  • Repeat step 3 to 5 until top<Max size-1
  • Read, item
  • Set top=top+1
  • Set stack[top]=item
  • Print "stack overflow"

Push Item in Stack in C++

	
  void push()
  {
   int item;
  if(top==size-1)
  {
  cout<<"\n Stack is full";
  }
  else
  {
  top=top+1;
  cout<<"\n\n Enter element in stack: ";
  cin>>s.item;
  s.stack[top]=s.item;
  }
  }

Prev Tutorial Next Tutorial

Google Advertisements
Download Projects

Google Adsense Advertisements

Buy 3 Year Old Domain, Tutorialday.com, SeosmoTools.com @$200

Buy This Ad Space @$50 per Month, Ad Size 300X250 Contact on: hitesh.xc@gmail.com WhatsApp no. 8882538826

Yahoo Advertisements