c++类栈的复制构造函数,大侠帮我看看那里出错了
#include<iostream>using namespace std;
class SqStack
{
private:
typedef struct LNode
{
int data;
struct LNode *next;
}*Linklist,LNode;
int count;
Linklist L;
public:
SqStack();
SqStack(SqStack &Sq);
~SqStack();
void Push(int e);
int Pop();
int empty();
};
inline SqStack :: SqStack()
{
count=0;
}
inline SqStack :: ~SqStack()
{
}
SqStack :: SqStack(SqStack &Sq)
{
Linklist q;
int count=0;
q=Sq.L;
while(!q)
{
if(count==0)
{
L=new LNode;
L->data=q->data;
L->next=NULL;
count++;
}
else
{
Linklist p;
p=new LNode;
p->data=q->data;
p->next=L;
L=p;
count++;
}
q=q->next;
}
}
void SqStack :: Push(int e)
{
if(count==0)
{
L=new LNode;
L->data=e;
L->next=NULL;
count++;
}
else
{
Linklist p;
p=new LNode;
p->data=e;
p->next=L;
L=p;
count++;
}
}
int SqStack :: Pop()
{
Linklist p;
int e;
p=L;
if(!p->next)
{
e=p->data;
delete p;
count--;
}
else
{
L=p->next;
e=p->data;
delete p;
count--;
}
return e;
}
int SqStack :: empty()
{
if(count==0)
return 1;
else
return 0;
}
int main()
{
SqStack S;
SqStack T;
SqStack W(T);
int e;
cout<<"请输入多个整数:"<<endl;
while(cin>>e)
{
if(e>=0)
S.Push(e);
else
T.Push(e);
}
cout<<"正整数:"<<endl;
while(!S.empty())
{
int Q;
Q=S.Pop();
cout<<" "<<Q;
}
cout<<endl;
cout<<"负整数:"<<endl;
while(!T.empty())
{
int Q;
Q=T.Pop();
cout<<" "<<Q;
}
cout<<endl;
while(!W.empty())
{
int Q;
Q=W.Pop();
cout<<" "<<Q;
}
return 0;
}