class Stack
{
private:
struct node
{
int data;
node *next;
}*top,*temp;
static int stackNum;
public:
Stack()
{
top=NULL;
stackNum++;
}
Stack(Stack& p)
{
stackNum++;
node *s,*q,*temp1,*head;
head=new node;
s=head;
q=p.top;
while(q)
{
temp1=new node;
temp1->data=q->data;
s->next=temp1;
s=temp1;
q=q->next;
}
s->next=NULL;
top=head->next;
}
~Stack()
{
delete top;
cout<<"the stack is destroyed"<<endl;
stackNum--;
}
void push()
{
temp=new node;
cin>>temp->data;
temp->next=top;
top=temp;
}
void pop()
{
int popData;
if (top==NULL)
cout<<"error"<<endl;
temp=top;
popData=temp->data;
top=top->next;
cout<<popData<<" is poped"<<endl;
delete temp;
}
void ShowStack()
{
temp=top;
cout<<"the stack:"<<endl;
while(temp)
{
cout<<temp->data<<" ";
temp=temp->next;
}
cout<<endl;
}
void ShowTop()
{
cout<<"the top of stack"<<endl;
cout<<top->data<<endl;
}
friend void stackNum();
};
int Stack::stackNum=0;
void stackNum()
{
cout<<"the number of stack is "<<Stack::stackNum<<endl;
}
{
private:
struct node
{
int data;
node *next;
}*top,*temp;
static int stackNum;
public:
Stack()
{
top=NULL;
stackNum++;
}
Stack(Stack& p)
{
stackNum++;
node *s,*q,*temp1,*head;
head=new node;
s=head;
q=p.top;
while(q)
{
temp1=new node;
temp1->data=q->data;
s->next=temp1;
s=temp1;
q=q->next;
}
s->next=NULL;
top=head->next;
}
~Stack()
{
delete top;
cout<<"the stack is destroyed"<<endl;
stackNum--;
}
void push()
{
temp=new node;
cin>>temp->data;
temp->next=top;
top=temp;
}
void pop()
{
int popData;
if (top==NULL)
cout<<"error"<<endl;
temp=top;
popData=temp->data;
top=top->next;
cout<<popData<<" is poped"<<endl;
delete temp;
}
void ShowStack()
{
temp=top;
cout<<"the stack:"<<endl;
while(temp)
{
cout<<temp->data<<" ";
temp=temp->next;
}
cout<<endl;
}
void ShowTop()
{
cout<<"the top of stack"<<endl;
cout<<top->data<<endl;
}
friend void stackNum();
};
int Stack::stackNum=0;
void stackNum()
{
cout<<"the number of stack is "<<Stack::stackNum<<endl;
}