singly linked list insertion
Please help me understand this code. Thanks.
It is trying to do insert in a sorted linked list.
void SLList: sortedInsert(int element)
{
//Find the place to insert
IntegerNode *p, *q;
for (p = myHead, q =0; //why do we need q? Don't we already
//have a null pointer in the last node?
(p != 0) && (element <= p->data( ); ) //can we omit the update
//instruction?
{q= p; //What does it mean? I don't know what
//would happen in q=p
p = p->next();
}
...}
Thank you for being help.