C++ Can';我不知道如何初始化SkipList的双指针
我需要创建一个skiplist数据结构,一个双向链表的2D矩阵。我的教授想让我们把每一行的头设为INT_MIN,每一行的尾设为INT_MAX,由两个指针指向,这两个指针分别是前卫和后卫。我在地址0xf71c3d:访问冲突写入位置0xCCCC遇到当前代码C++ Can';我不知道如何初始化SkipList的双指针,c++,pointers,constructor,skip-lists,C++,Pointers,Constructor,Skip Lists,我需要创建一个skiplist数据结构,一个双向链表的2D矩阵。我的教授想让我们把每一行的头设为INT_MIN,每一行的尾设为INT_MAX,由两个指针指向,这两个指针分别是前卫和后卫。我在地址0xf71c3d:访问冲突写入位置0xCCCC遇到当前代码异常0xc0000005时出错 我假设这意味着指针的设置方式有问题,但我不知道为什么。我的程序无法通过构造函数,到目前为止,我试着调试它,它说这个={SkipList*const | 0x005efddc}0x005efddc,这看起来也是个问题。
异常0xc0000005时出错
我假设这意味着指针的设置方式有问题,但我不知道为什么。我的程序无法通过构造函数,到目前为止,我试着调试它,它说这个={SkipList*const | 0x005efddc}0x005efddc,这看起来也是个问题。
这是我在.cpp文件和.h文件中的构造函数
建造商:
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文件:
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);
};
类SkipList
{
私人:
类势垒
{
公众:
//SNode将int存储为数据
显式SNode(int数据);
//用于SNode的数据
int数据;
//链接到下一个SNode
斯诺德*下一个;
//链接到上一个SNode
斯诺德*先前;
//链接到上一级
SNode*upLevel;
//链接到下一级
SNode*下层;
};
斯诺德**前卫;
斯诺德**后挡板;
公众:
void addBefore(SNode*newNode,SNode*nextNode);
斯基普利斯特();
虚拟~SkipList();
bool-Add(int-data);
friend ostream&Operator在默认构造函数中,指针未初始化,但您尝试使用frontGuards[0]访问它
。某些编译器可能会重复使用0xCCCC
作为标记值,以显示指针在初始化之前的使用时间,至少在调试版本中是这样。因此,当您在错误消息中看到该值时,您应该问自己:我在哪里初始化了该指针?我不知道如何初始化指针。这是一个错误SNode对象上的双指针最终需要指向上下,我想,但我还没有到那个点。我在默认构造函数中真正想做的是让frontGuards和rearGuards保持它们的INT_MIN和INT_MAX值,同时能够使用frontGuards->next指向列表中的第二个节点.双指针是否必须指向另一个指针?