Это мой конструктор, который должен "динамически распределять массивы frontGuards и tailGuards, создавать специальные объекты SNode * в качестве защитников, t ie все объекты SNode вместе (как prev-next, так и up-down)":
// SkipList constructor
SkipList::SkipList(int Depth) {
// The depth of the SkipList is given in the constructor,
// so frontGuards and rearGuards will have to be dynamically
// allocated arrays, using frontGuards = new SNode*[depth];
// where for the level L0, the frontGuard will be frontGuards[0]
// and rear guard frontGuards[0]
FrontGuards = new SNode* [Depth];
RearGuards = new SNode* [Depth];
FrontGuards[0] -> Data = INT_MIN;
RearGuards[0] -> Data = INT_MAX;
FrontGuards[0] -> Next = RearGuards[0];
RearGuards[0] -> Prev = FrontGuards[0];
FrontGuards[0] -> Prev = nullptr;
RearGuards[0] -> Next = nullptr;
FrontGuards[0] -> UpLevel = nullptr;
FrontGuards[0] -> DownLevel = nullptr;
RearGuards[0] -> UpLevel = nullptr;
RearGuards[0] -> DownLevel = nullptr;
}
Это мой .h:
private:
// private SNode
// defined in .cpp as SkipList::SNode::SNode(int Data) ...
struct SNode {
// SNode stores int as data
explicit SNode(int Data);
// data for SNode
int Data;
// link to Next SNode
SNode *Next;
// link to Prev SNode
SNode *Prev;
// link to up one level
SNode *UpLevel;
// link to down one level
SNode *DownLevel;
};
using Snode = struct Snode;
// Depth of SkipList
int Depth;
// array of Depth SNode* objects as FrontGuards linking levels
SNode **FrontGuards;
// array of Depth SNode* objects as RearGuards linking levels
SNode **RearGuards;
}
Я получаю сообщение об ошибке: EXC_BAD_ACCESS (code = EXC_I386_GPFLT) для строки "FrontGuards [0] -> Data = INT_MIN;" и я не уверен почему.