I've seen better worded instructions, but I've seen worse too. I assume that List.h is a given file and dictates how you are to implement a list. USUALLY, the term list is used to indicate a linked list, as implied by logicalhippo, but I've seen lists implemented as an array before. After all, the word list is about as specific as the word house. Lists implemented as arrays suffer from all the woes of an array (difficult to "expand" at will--or inability to expand--depending on your point of view, problem of overreading, need to flag deleted entries or shift remaining entries after deletions/insertions into the middle, etc), and benefit from all the good points of the virtues of an array (uh, random access only I guess).
No matter how the list is implemented however, the concept of setPos() is to identify a given element/node/link of the list that contains the specific value sent to setPos() as an argument. If the list is implemented as an array, then currentPos will be an integer related to the offset from the beginning of the array, whereas if the list is implemented as a linked list, then currentPos will be a pointer (or an iterator if the STL list class is used--STL containers typically implement the "end" iterator to be the one just after the "last" entry) containing the address of the node/link that has the desired value.
If you use a list implemented as an array, then use a loop to search the elements of the array. At the end of the loop, the loop variable will be the value of currentPos - 1, unless the value wasn't found, in which case the value of currentPos will be the same as the value of the loop variable.
Code:
for(i = 0; i < length; ++i)
{
if(array[i] == desired value)
break;
}
if(i == length)
currentPos = i;
else
currentPos = i +1;
Alternatively, if you implement the list as a linked list, then the nodes will need to have a numerical indicator, which will be used as the ordinal value, as well as a data value.
Code:
struct Node
{
int ordinalPosition;
//data;
Node * next;
//optional second Node pointer if using doubly linked list
};
class List //1templated to be able to hold any value type
{
public:
int currentPos;
int numNodes;//variable to hold number of nodes/links in list
void setPos(argument type);
//etc
};
void List::setPos(argument type)
{
Node * current = head;
while(current != Null && current->data != desired value)
{
current = current->next;
}
if(current == NULL)//desired value not found
currentPos = numNodes + 1;
else
currentPos = current->ordinalPosition;
}
The most frequent use of the concept of currentPos is to indicate the address of the node/link with the desired value, not the ordinal position of the node/link with the desired value. But so be it. If that's what you need to do, then that's what you need to do.