我在返回指向结构的指针时遇到问题。有人可以解释我做错了什么吗?我希望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);
}
}