I need to create a skiplist data structure, a 2D matrix of doubly linked lists. My professor wants us to have the head of each row to be INT_MIN and the tail of each row to be INT_MAX, being pointed to by double pointers named frontGuards and rearGuards. I'm getting an error with my current code Exception 0xc0000005 encountered at address 0xf71c3d: Access violation writing location 0xcccccccc
which I'm assuming means something is wrong with how I have my pointers set up but I can't figure out why. My program can't get past the constructor, and so far I've tried debugging to look at this and it's saying that this = {SkipList *const | 0x005efddc} 0x005efddc which also looks like a problem.
here is my constructor in the .cpp file and my .h file
constructor:
SkipList::SkipList() // default constructor that sets front and rear guards
{
frontGuards[0]->data = INT_MIN;
rearGuards[0]-> data = INT_MAX;
frontGuards[0]->next = rearGuards[0];
rearGuards[0]->previous = frontGuards[0];
frontGuards[0]->previous = nullptr;
rearGuards[0]->next = nullptr;
}
.h file:
class SkipList
{
private:
class SNode
{
public:
// 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 *previous;
// link to up one level
SNode *upLevel;
// link to down one level
SNode *downLevel;
};
SNode **frontGuards;
SNode **rearGuards;
public:
void addBefore(SNode *newNode, SNode *nextNode);
SkipList();
virtual ~SkipList();
bool Add(int data);
friend ostream &operator<<(ostream &os, const SkipList &list);
};
Currently I am only trying to get all the functions of the class working with a single doubly linked list before I move on to the matrix. I'm sorry if this is something simple to figure out I'm still very naive but I can't get help from my school's tutoring center because of my job and no school because of holiday. I've never used double pointers and I don't understand why I need to use them or the front/rear guards for a skiplist or what is going on with my code. I apologize for anything that seems mundane or redundant. What does it mean that the pointer isn't initialized? Especially if I'm trying to have it point at data with frontGuards[0]->data = INT_MIN
UPDATE: I tried initializing the pointers to nullptr in the header file but that didn't help, still produces the same error
User contributions licensed under CC BY-SA 3.0