标题:里面的复制构造函数那里出错了,大侠帮帮忙
只看楼主
zqllsszhuqi
Rank: 2
等 级:论坛游民
帖 子:26
专家分:45
注 册:2010-3-29
结帖率:75%
已结贴  问题点数:0 回复次数:2 
里面的复制构造函数那里出错了,大侠帮帮忙
#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;
        getchar();
    }
    return 0;

}
搜索更多相关主题的帖子: private include public count class 
2011-10-17 22:56
yuccn
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:何方
等 级:版主
威 望:167
帖 子:6809
专家分:42393
注 册:2010-12-16
得分:2 
inline SqStack :: SqStack()
{
    L = NULL;
    count=0;
}

SqStack :: SqStack(SqStack &Sq)
{   
    L = NULL;
    Linklist q;
    int count=0;
    ……
    ……
}

注意红色的代码

我行我乐
我的博客:
http://blog.yuccn. net
2011-10-18 12:23
zqllsszhuqi
Rank: 2
等 级:论坛游民
帖 子:26
专家分:45
注 册:2010-3-29
得分:0 
虽然不对,现在我已经解决了,还是谢谢你!!!
2011-10-21 08:41



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-352751-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 1.164574 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved