I am having issue returning a pointer to a struct. Can some explain what I am doing wrong? I want the search( ) to return a pointer to the matching input. That will be stored into a vector in case their are duplicates in the "array". This seems to work however I cannot get the "data" from the pointer returned?
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
}
}
line 13 of the search function.
If recursively called search finds something, where will result go?
In fact, if it will not find needed data immideatly, it will return random number from the stack.
So you trying to dereference a pointer to random memory address
And like toum said, you don't have an "element" member in "Node" struct. Did you misspelled "data"?