|
Pictorial representation of the insert algorithm:
|
All other cases can be handle by the insertion algorithm described above.
if ( head == NULL ) { .... } |
Handle it in the same way as in the "insert at tail" example.... |
if ( newElem->value <= head->value ) { .... } |
Handle it in the same way we have handle insertion at the head of a list. |
if ( head == NULL ) { code to handle insert for special case 1 } else if ( newElem->value <= head->value ) { code to handle insert for special case 2 } else { code to handle insert for all other cases } |