in this snippet q isnt used but it could be very useful as it points to the parent node of the current node.
Code:
void SLList: sortedInsert(int element)
{
IntegerNode *Current,*Parent;
for (Current = myHead, // make current point to head of list
Parent=NULL; // head of list has no parent.
(Current != NULL) // make sure that there is something pointed to
&& (element <= Current->data( ); ) // comparison
{
Parent=Current; // now both pointers point to same node... current
Current = Current->next(); // move onto next node in list.
}
}
now you can find where to insert all you need implement is how to insert. This is where knowing the address of the parent of the current node is necessary.