I am just trying to figure it out, would this work?
I know for the parameters you need the position, and I guess the Node, but would there be a third param?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
template<class ItemType>
ItemType LinkedList<ItemType>::GetEntry(int position, Node* curPtr) constthrow(PreconditionViolatedException)
{
Node<ItemType>* node_ptr = GetNodeAt(position);
if(curPtr != NULL){
if(node_ptr==curPtr->GetItem()){
return node_ptr->GetItem();
elsereturn GetEntry(position, curPtr->GetNext());
}
else{
const string message = "GetEntry() called with an empty list or invalid position.";
throw(PreconditionViolatedException(message));
}
}
Below is the original function
1 2 3 4 5 6 7 8 9 10 11 12
template<class ItemType>
ItemType LinkedList<ItemType>::GetEntry(int position) constthrow(PreconditionViolatedException)
{
constbool able_to_get = (position >= 1) && (position <= item_count_);
if (able_to_get) {
Node<ItemType>* node_ptr = GetNodeAt(position);
return node_ptr->GetItem();
}
const string message = "GetEntry() called with an empty list or invalid position.";
throw(PreconditionViolatedException(message));
}