| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 637 人关注过本帖
标题:谁帮我改改这个编译错误啊。
只看楼主 加入收藏
做个好人
Rank: 1
等 级:新手上路
帖 子:23
专家分:1
注 册:2010-4-9
结帖率:33.33%
收藏
 问题点数:0 回复次数:2 
谁帮我改改这个编译错误啊。
我在VC6.0上写的。


单链表问题。



#include<iostream>
#include<string>
using namespace std;


class SLNode                // 节点类
{
public:
    int data;      //               
    SLNode *next;   //


    SLNode (SLNode * nextNode=NULL)             //构造函数。。
    {
        next=nextNode;
    }
    SLNode (const int &  item,SLNode *   nextNode=NULL)     //  构造函数。。。
    {
        data=item;
        next=nextNode;
    }
};

class SLList:public SLNode                                 // 单链表的类定义。
{
private:
    SLNode * head,*tail;                                   //    头结点。尾结点。
    SLNode * currptr ;                                     //    当前指针。
    int size;   
public:
    SLList (void)
    {
        head=tail=currptr=new SLNode();
        size =0;
    }
    SLList(int  &  item)         //gou zhao  han  shu
    {
        tail=currptr=new SLNode(item);
        head=new SLNode(currptr);
        size=1;
    };
    ~SLList(void);
    bool IsEmpty(void) const {return head->next==NULL;}; //  链表是否为空
    void SetStart(void){currptr=head;}
    void SetEnd(void){currptr=tail;}
    int length(void){return size;}             //  返回链表长度。
    void Next(void)                   //  当前指针指向下一个节点
    {
        if(currptr==tail)
        {
            cout<<" no next node!"<<endl;
            return ;
        }
        currptr=currptr->next;
    }
    void Prew(void)            // 当前指针指向前一个节点。
    {
        if(IsEmpty()||currptr==head)
        {
            cout<<"no previous node!"<<endl;
            return ;
        }
        SLNode *temp=head;
        while(temp->next!=currptr)
            temp=temp->next;
        currptr=temp;
    }
    bool Find(int k,int & item)           //  查找。
    {
        if(k<1||IsEmpty())
        {
            cout<<"Invalid number or empty list!"<<endl;
            return false;
        }
        currptr=head;
        for(int i=1;i<=k;i++)
        {
            currptr=currptr->next;
        }
        item=currptr->data;
        return true;
    }
    int Search (const int  & item)            // 查找返回。
    {
        if(IsEmpty())
        {
            cout<<"list empty!"<<endl;
        }
        currptr=head;
        int k=0;
        while(currptr->next!=NULL)
        {
            k++;
            if(currptr->data==item)
            {
                return k;
            }
            currptr=currptr->next;
        }
        if(currptr->next==NULL)
        {
            cout<<"no find!"<<endl;
        }
    }
    void Insert( int & item)       //  dang qian jie dian zhi hou  cha ru xin jie dian
    {
        currptr->next=new SLNode(item,currptr->next);
        if(tail==currptr)
            tail=currptr->next;

        size++;
    }                                                                                                      
    void InsertFromTail(const int & item)   //biao wei cha ru
    {
        tail->next=new SLNode(item ,NULL);
        tail=tail->next;
        size++;
    }
    void InsertFromHead(const int & item)         //  biao tou cha ru
    {
        if(IsEmpty())
        {
            head->next=new SLNode (item,head->next);
            tail=head->next;
        }
        else
            head->next=new SLNode (item,head->next);
        size ++;
    }
    bool Delete(int &  de_item) //  shan chu dang qian jie dian de hou ji jie dian
    {
        if(currptr==tail||IsEmpty())
        {
            cout<<"no next or empty list!"<<endl;
            return false ;
        }
        SLNode *temp=currptr->next;
        currptr->next=temp->next;
        size--;
        de_item=temp->data;
        if(temp==tail) tail=currptr;
        delete temp;
        return true;
    }
    bool DeleteFromHead(int  & de_item)    // shan chu di yi ge jie dian
    {
        if(IsEmpty())
        {
            cout<<"empty list!"<<endl;
            return false;
        }
        SLNode * temp=head->next;
        head->next=temp->next;
        size --;
        de_item=temp->data;
        if(temp==tail)
            tail=head;
        delete temp;
        return true;
    }
    bool DeleteFromTail(int & de_item)
    {
        if(IsEmpty())
        {
            cout<<"empty list"<<endl;
            return false ;
        }
        SetEnd();
        Prew();
        de_item=tail->data;
        currptr->next=NULL;
        size --;
        delete tail;
        tail=currptr;
        return true;
    }

            
};
int main(void)
{
   SLList  list1;
   int a=1;
   int  &b=a;
   list1.Insert(b);                                //  改了之后还是连接不过去。            



    return 0;
}



        
            













[ 本帖最后由 做个好人 于 2010-4-22 12:18 编辑 ]
搜索更多相关主题的帖子: 编译 改改 
2010-04-21 23:28
cnfarer
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:179
帖 子:3330
专家分:21157
注 册:2010-1-19
收藏
得分:0 
(是你自己写的吗?)光让别人看代码,只能应付作业!没有多大用途的!关键是自己要下功夫啊!

void Insert( int & item) 这是定义
当然这样Insert(1)不行了!回去看看“&”是做什么的吧?!

★★★★★为人民服务★★★★★
2010-04-22 06:52
做个好人
Rank: 1
等 级:新手上路
帖 子:23
专家分:1
注 册:2010-4-9
收藏
得分:0 
课本上的例题。
2010-04-22 11:58
快速回复:谁帮我改改这个编译错误啊。
数据加载中...
 
   



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

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