I am trying to write a search function for an ordered linked list. I have the following:
A TestLL class contains ListNode *head; The ListNode structure contains int Key, double data Value, and ListNode *next. I'm trying to get the function to return the double value found in the dataValue field of the structure found, or -1.0 if the node is not found. My code won't comppile and i'm not sure why. I'm new to linked lists and data structures so any help with my code would be appreciated!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
double TestLL::Search(int key)
{
ListNode *temp = head;
//search for the key
while( temp != NULL && key != temp -> key ) {
temp = temp -> next;
}
//check to see if I found the node
if( key == temp -> key) {
//return the appropriate value
return temp;
} else {
//return the appropriate sentinel value
return -1.0;
}
}