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;
}``````

a123456678 2016-03-06 11:47:11 2410 0
1 条回答

• ``````#include

using namespace std; //加上这句

template < class Elem >
class AList : public list

或者

#include
template < class Elem >
class AList : public std::list //改成这样
``````
2019-07-17 18:54:21
赞同 展开评论 打赏

756
1
0
339
1
0
428
1
0
379
1
0
394
1
0
1386
1
0
435
1
0
624
1
0
1006
1
0
420
1
0

相关电子书

GPON Class C++ SFP O;T Transce 立即下载
GPON Class C++ SFP OLT Transce 立即下载