Linked List program implementation

Hi All,

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 :)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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?
   
 } 
Last edited on
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 

Last edited on
**Correct sll1....should be strLinkedList.

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.

string * testPtr;
Last edited on
To save a lot of time to and fro with Qusteions - just post your code and we can go from there.
Topic archived. No new replies allowed.