構造体へのポインタを返す際に問題が発生しました。私が間違っていることを説明できる人はいますか?search()
一致する入力へのポインタを返したい。それらが「配列」内で重複している場合に備えて、それはベクトルに格納されます。これは機能しているようですが、返されたポインタから「データ」を取得できませんか?
struct Node
{
int data;
Node *left;
Node *next;
};
vector<Node *> array;
void find(int & input)
{
currentSize = 0;
vector<Node *> hold;
for( int i = 0; i < array.size( ); i++ ){
if(search(array[i], input) != NULL)
{
hold.push_back(search(array[i], input));
}
else{
cout << "The Key is not found" << endl;
}
}
for(int i = 0; i < hold.size(); i++)
{
cout << hold[i] << endl;
//Problem here:: I want to see the "data" that the search function returned not the hex value
}
}
Node * search(Node * x, const int & input)
{
if( x == NULL )
{
return NULL;
}
else
{
if(input == x->element)
{
return x;
}
search(x->left, input);
search(x->next, input);
}
}