加入收藏 | 设为首页 | 会员中心 | 我要投稿 PHP编程网 - 黄冈站长网 (http://www.0713zz.com/)- 数据应用、建站、人体识别、智能机器人、语音技术!
当前位置: 首页 > 服务器 > 安全 > 正文

《数据结构》第二章线性表设计2:同学博客中问题求解

发布时间:2021-05-26 07:47:20 所属栏目:安全 来源:网络整理
导读:????? 各位同学,为了创建一个同学们相互学习讨论的气氛,现将同学们在自己博客是碰到的问题放出来,欢迎大家来指导,并致谢谢。请大家在本文章中集中给出自己意见。谢谢。要提醒大家的是,程序是有错误,我想也是大家可能会有的,具有一定的代表性,所以

????? 各位同学,为了创建一个同学们相互学习讨论的气氛,现将同学们在自己博客是碰到的问题放出来,欢迎大家来指导,并致谢谢。请大家在本文章中集中给出自己意见。谢谢。要提醒大家的是,程序是有错误,我想也是大家可能会有的,具有一定的代表性,所以大家要考虑。

1.第二章 线性表设计2 程序求调试错误解决

同学链接:??? ? ?? 我真的不知道错在哪里


    #include<iostream>  
    using namespace std;  
      
    template<class T>  
    struct Student  
    {  
        T data;  
        Student<T> * next;  
    };  
      
    template<class T>  
    class LinkList  
    {  
    public:  
        LinkList();  
        LinkList(T a[],int n);  
        ~LinkList();  
        void Insert(int i,T x);  
        T Delete(int i);  
        void PrintList();  
    private:  
        Student<T> * first;  
    };  
      
    template<class T>  
    LinkList<T>::LinkList()  
    {  
        first=new Student;  
        first->next=NULL;  
    }  
      
    template<class T>  
    LinkList<T>::LinkList(T a[],int n)  
    {  
        first=new Student;first->next=NULL;  
        for(i=0;i<n;i++)  
        {  
            s=new Student;s->data=a[i];  
            s->next=first->next;first->next=s;  
        }  
    }  
      
    template<class T>  
    void LinkList<T>::Insert(int i,T x)  
    {  
        p=first;count=0;  
        while(p!=NULL&&count<i-1)  
        {  
            p=p->next;  
            count++;  
        }  
        if(p==NULL)throw"输入错误"  
            else{  
            s=new Student;s->data=x;  
            s->next=p->next;p->next=s;  
        }  
    }  
      
    template<class T>  
    T LinkList<T>::Delete(int i)  
    {  
        p=first;count=0;  
        while(p!=NULL&&count<i-1)  
        {  
            p=p->next;  
            count++;  
        }  
        if(p==NULL||p->next==NULL)throw"输入错误";  
        else{  
            q=p->next;x=q->data;  
            p->next=q->next;  
            delete q;  
            return x;  
        }  
    }  
      
    template<class T>  
    void LinkList<T>::PrintList()  
    {  
        p=first->next;  
        while(p!=NULL)  
        {  
            cout<<p->data;  
            p=p->next;  
        }  
    }  
      
    void main( )    
    {    
        int score[5]={10,20,40,50,60};    
        LinkList<int> ScoreList(score,5);  
        ScoreList.PrintList();  
        ScoreList.Insert(2,30);  
        ScoreList.PrintList();  
        ScoreList.Delete(4);  
        ScoreList.PrintList();  
    }  
,翻了很多遍了都还是运行不了,所以请老师及各位大臣指点。

(编辑:PHP编程网 - 黄冈站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读