我有一个名为堆的模板类。我的问题是我想在底部实现插入功能。但我无法到达值向量的成员变量。当我写出值[hole / 2] .tall时它无法到达它(高位变量在写入点后不会直接出现)。那么有人可以解释一下吗?
template <class Comparable>
class Heap
{
...
private:
// I have this vector
vector <heightNode <Comparable>> Values
};
template <typename Comparable>
struct heightNode
{
Comparable tall;
Comparable label;
heightNode(const Comparable & t = Comparable(), const Comparable & la = Comparable()): tall(t),label(la) {}
heightNode(const heightNode & rhs): tall(rhs.tall),label(rhs.label){}
};
template <class Comparable>
void Heap <Comparable>:: insert (const Comparable & value, const int & label)
{
if(isFull())
{
cout <<"Heap is Full";
}
else
{
++currentSize;//hole is an index we will put it to the last point in the vector.
for(int hole=currentSize; hole>1 && (value > Values[hole/2].tall)); hole/=2 )
{
}
}
}
答案 0 :(得分:1)
这个
for(int hole=currentSize; hole>1 && (value > Values[hole/2].tall)); hole/=2 )
包含多余的圆形闭合支架;做到这一点
for (int hole=currentSize; hole>1 && (value > Values[hole/2].tall); hole/=2)