Turning a loop into a recursion is pretty simple: the body of the loop becomes the function body, and the loop-variable becomes the parameter passed from one recursion to the next.
The loop you have is not the best to lead you into making it a recursion, may I suggest this alternative which is pretty easy to turn into a recursion:
NodeType<ItemType>* traverse = head;
while(true) {
if( traverse == NULL ) {
NodeType<ItemType>* nodePTR = new NodeType<ItemType>(item);
nodePTR->next = head;
head = nodePTR;
length++;
return true;
} else if( traverse->info == item ) {
return false;
}
traverse = traverse->next;
}
Turning the above into a recursion should be a piece of cake, with those two hints given above.
mike_2000_17
Posting Virtuoso
2,139 posts since Jul 2010
Reputation Points: 1,634
Solved Threads: 457