Program to generate a stack and basic operations of stack in C++.

#include<iostream>
#include<cstring>
using namespace std;
class Stack
{
int top;
string arr[3];
public:
Stack()
{
top=0;
cout<<"Stack is instantiated"<<endl;
}
bool isfull()
{
return(top>3);
}
bool isempty()
{
return (top==-1);
}
void push(string str)
{
if(isfull())
{
cout<<"stack is full";
return;
}
else
arr[top]=str;
top++;
}
void pop()
{
top--;
if(isempty())
{
cout<<"cannot be popped";
return;
}
else
cout<<arr[top];
}
};
main()
{
Stack S;
int a,i=0;
string str;
char b='y';
while(b=='y')
{
cout<<"1.Push the names"<<endl<<"2.Pop the names"<<endl;
cin>>a;
if(a==1)
{
cout<<"Enter the name:";
getline(cin,str);
cin>>str;
S.push(str);
}
if(a==2)
{
S.pop();
}
cout<<"continue?(y/n)";
cin>>b;
}
}
Advertisements

3 thoughts on “Program to generate a stack and basic operations of stack in C++.

  1. I simply want to tell you that I am just beginner to blogging and actually liked you’re web site. Probably I’m likely to bookmark your site . You amazingly have amazing stories. With thanks for sharing your web-site.

  2. I simply want to mention I am new to blogging and absolutely liked your blog site. Probably I’m planning to bookmark your blog post . You definitely come with really good well written articles. Thanks a bunch for sharing with us your web page.

  3. you’re really a good webmaster. The web site loading speed is incredible. It seems that you’re doing any distinctive
    trick. In addition, The contents are masterpiece.
    you have done a great activity in this topic!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s