|
|
|
|
|
|
|
if (fromPtr == NULL)
return NULL; // Base case
else // Recursive case
{
toPtr = new NodeType;
toPtr->component = fromPtr->component;
toPtr->link = PtrToClone(fromPtr->link);
return toPtr;
}
} |
|
|
|
|
|
|
|
|
Let's perform a code walk-through of the function call |
|
|
|
|
|
|
|
|
newListHead = PtrToClone(head); |
|
|
|
|
|
|
|
|
using the following list: |
|
|
|
|
|
|
|
|
Call 1: fromPtr points to the node containing 49 and is not NULL. A new node is allocated and its component value is set to 49. |
|
|
|
|
|
|
|
|
Execution of this call pauses until the recursive call with actual parameter fromPtr->link has been completed. |
|
|
|
|
|
|
|
|
Call 2: fromPtr points to the node containing 50 and is not NULL. A new node is allocated and its component value is set to 50. |
|
|
|
|
|