LCRS ツリーを表すクラスを作成していますが、検索機能に問題があります。ここに私がこれまでに持っているものがあります:
lcrs.h:
using namespace std;
#include <cstdlib>
#include <iostream>
class node{
public:
int data;
node *right;
node *below;
};
class lcrs{
public:
int height;
node *root;
bool search(int);
void print(lcrs);
void insert(int);
void del(int);
lcrs()
{
root = NULL;
}
};
これは lcrs.cpp です。
using namespace std;
#include "lcrs.h"
bool lcrs::search(int x)
{
if(root == NULL)
return false;
else
{
if(root->data == x)
return true;
else
{
while(right != NULL && below != NULL)
{
if(right->data == x || below->data == x)
return true;
}
return false;
}
}
}
これは私のエラーメッセージです:
lcrs.cpp: In member function ‘bool lcrs::search(int)’:
lcrs.cpp:21:26: error: ‘below’ was not declared in this scope
lcrs.cpp:23:15: error: request for member ‘data’ in ‘std::right’, which is of non-class type ‘std::ios_base&(std::ios_base&)’
最初にオブジェクトを作成しないと「right」と「below」のメンバーにアクセスできないことは理解していますが、それらにアクセスする別の方法はありますか? 私は単に「データ」の内容を確認しようとしています。最初にノードをインスタンス化せずにこれを行う方法がわかりません。
よろしくお願いいたします。