I know this is probably a basic question but I am stuck. I am a function that is passed an integer and matches that integer with a linked list node and returns the contents of the node. I have written the function and want to test it, but I am not sure how to implement it in main() as the client.
Below are my functions. Any help is appreciated. I need general direction and am not looking for someone to finish my program :)
template<typename NODE>
ListNode<NODE> *List<NODE>::retrieve(int token)
{
//first is a pointer to the first node and is a member of my class.
//last is a pointer to the last node and is a member of my class.
//count is a member of my class that is calculated when nodes are added.
ListNode< NODE > *currentPtr = first;
for(int i = count - 1; i > token && currentPtr != NULL; i--)
{
currentPtr = currentPtr->nextPtr;
}
return currentPtr;
}
int main()
{
List< string > strLinkedList;
int position;
//Read in list values from a file
readInput(strLinkedList);
//Retrieve data from node 2
strLinkedList.retrieve(2); //???How to call the retrieve function?
}
For the record :
The function does not actuualyl return the contents of the node. It returns a pointer to the node
(which may be NULL if there is an error)
What is this line supposed to do (have you got a name mixup here?):
1 2
//Read in list values from a file
readInput(sll1); //What is SLL1
I tried the same implementation with int and still can't get it to work. I tried casting the return to a string, but still get data mismatch errors. I tried creating a pointer to a string named testPtr and assign the result to that, but I guess I am not sure what datatype to make testPtr since it is returning a ptr to a node instead of a ptr to a string, even though the node contains a string value.