クラスオブジェクトにある配列にintを挿入しようとしていますが、何が間違っているのか理解できません。私のコードの現在の状態では、intが配列に挿入されることはありません。
基本的に私がやろうとしているのは、insert(int)を呼び出すと、配列にスペースが残っているかどうかを確認し、ある場合はそれを追加します。そうでない場合は、さらに8つのスペースで再割り当てします。配列。
ここにいくつかの関連するクラス情報があります
private:
unsigned Cap; // Current capacity of the set
unsigned Num; // Current count of items in the set
int * Pool; // Pointer to array holding the items
public:
// Return information about the set
//
bool is_empty() const { return Num == 0; }
unsigned size() const { return Num; }
unsigned capacity() const { return Cap; }
// Initialize the set to empty
//
Set()
{
Cap = Num = 0;
Pool = NULL;
}
これが私が取り組んでいるコードです
bool Set::insert(int X)
{
bool Flag = false;
if (Num == Cap)
{
//reallocate
const unsigned Inc = 8;
int * Temp = new int[Cap+Inc];
for (unsigned J=0;J<Num;J++)
{
Temp[J] = Pool[J];
}
delete [] Pool;
Pool = Temp;
Cap = Cap+Inc;
}
if(Num < Cap)
{
Pool[Num+1] = X;
Flag = true;
}
return Flag;
}