纵横车 2015-05-29 08:55 采纳率: 100%
浏览 1593
已采纳

C++数据结构与算发线性表List问题。

看《数据结构与算法分析》,用书上的代码创建线性表的顺序表。
可是编译出现错误,求解答。
AList.h

 #include <list>
template < class Elem >
class AList : public List<Elem>
{
private:
    int maxSize;
    int listSize;
    int fence;
    Elem* listArray;
public:
    AList(int size=DefaultListSize)
    {
        maxSize = size;
        listSize = fence = 0;
        listArrary = new Elem[maxSize];
    }
    ~AList(void)
    {
        delete [] listArrary;
    }
    void clear()
    {
        delete [] listArrary;
        listArrary = fence = 0;
        listArrary = new Elem[maxSize];
    }
    bool insert(const Elem&);
    bool append(const Elem&);
    bool remove(Elem&);
    void setStart()
    {
        fence = 0;
    }
    void setEnd()
    {
        fence = listSize;
    }
    void prev()
    {
        if(fence != 0)
            fence--;
    }
    void next()
    {
        if(fence <= listSize)
            fence++;
    }
    int liftLength() const
    {
        return fence;
    }
    int right() const
    {
        return listSize - fence;
    }
    bool setPos(int Pos)
    {
        if((Pos >= 0) && (Pos <= listSize))
            fence = pos;
        return (pos >= 0) && (pos <= listSize)
    }
    bool getValue(Elem& it) const
    {
        if(rightLength() == 0)
            return false;
        else
        {
            it = listArrary[fence];
            return true;
        }
    }
    void print() const
    {
        int temp = 0;
        cout<<"< ";
        while(temp < fence)
            cout<<listArrary[temp++]<<" ";
        cout<<"| ";
        while(temp < listSize)
            cout<<">\n"
    }
};

AList.cpp

 #include "AList.h"
template <class Elem>
bool AList<Elem>::insert(const Elem& item)
{
    if(listSize == maxSize)
        return false;
    for(int i=listSize;i>fence;i++)
        listArrary[i] = listArrary[i-1];
    listArrary[fence] = item;
    listSize++;
    return true;
}
template <class Elem>
bool AList<Elem>::append(const Elem& item)
{
    if(listSize == maxSize)
        return false;
    listArrary[listSize++] = item;
    return true;
}
template <class Elem>
bool AList<Elem>::remove(Elem& it)
{
    if(rightLength() == 0)
        return false;
    it = listArrary[fence];
    for(int i=fence;i < listSize-1;i++)
        listArrary[i] = listArrary[i+1];
    listSize--;
    return true;
}

编译错误为:alist.h(4): error C2143: 语法错误 : 缺少“,”(在“<”的前面)

  • 写回答

7条回答

  • ZY5A59 2015-05-29 12:59
    关注

    #include

    using namespace std; //加上这句

    template < class Elem >
    class AList : public list

    或者

    #include
    template < class Elem >
    class AList : public std::list //改成这样

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(6条)

报告相同问题?

悬赏问题

  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败