Tuesday 8 April 2014

Data Structure C++ Programming Code of Stack Insertion

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();

int stack[100],loc,top,item,max=100;


cout<<"\n------ Stack Insertion using Array ------";
cout<<"\n\nEnter Value of Stack Top : ";
cin>>top;

if(top>=max)
{
cout<<"\nStack is Full";
getch();
return;
}

cout<<"\nEnter Elements in Stack :\n";
for(loc=0;loc<=top;loc++)
{
cin>>stack[loc];
}

cout<<"\nEnter Item you want to Insert : ";
cin>>item;

top=top+1; //Increment the Top
stack[top]=item;         //Insert Element

cout<<"\nStack After Insertion :\n";
for(loc=0;loc<=top;loc++)
{
cout<<stack[loc]<<endl;
}
getch();
return;
}

No comments:

Post a Comment