R
remlostime
I have written a SplayTree class, what makes me wonder is when I
compiled it, it has something errors:
error:'SplayNode' has not been declared
you can see the code below that the SplayNode has been declared in
private, why? And how can i fix it?
And I have tried another way that declared the SplayNode outside the
SplayTree and it works well. It really makes me confused.
/*
struct SplayNode
{
SplayNode *left, *right;
int key;
};
SplayNode *root, *nullNode;
*/
class SplayTree
{
public:
SplayTree()
{
nullNode = new SplayNode;
nullNode->left = nullNode->right = nullNode;
root = nullNode;
}
void rotateLeft(SplayNode *&node)
{
SplayNode *p = node->right;
node->right = p->left;
p->left = node;
node = p;
}
private:
struct SplayNode
{
SplayNode *left, *right;
int key;
};
SplayNode *root, *nullNode;
};
compiled it, it has something errors:
error:'SplayNode' has not been declared
you can see the code below that the SplayNode has been declared in
private, why? And how can i fix it?
And I have tried another way that declared the SplayNode outside the
SplayTree and it works well. It really makes me confused.
/*
struct SplayNode
{
SplayNode *left, *right;
int key;
};
SplayNode *root, *nullNode;
*/
class SplayTree
{
public:
SplayTree()
{
nullNode = new SplayNode;
nullNode->left = nullNode->right = nullNode;
root = nullNode;
}
void rotateLeft(SplayNode *&node)
{
SplayNode *p = node->right;
node->right = p->left;
p->left = node;
node = p;
}
private:
struct SplayNode
{
SplayNode *left, *right;
int key;
};
SplayNode *root, *nullNode;
};