It is often important to determine if a list is empty. This can be done
in many ways, but only two are worth mentioning. If either the lh_TailPred&
field is pointing to the list header or the ln_Succ& field of the node
lh_Head& is pointing to is zero, then the list is empty.
In code, for example, these methods would be written as follows:
'You can use this method...
IF PeekL&(list&, lh_TailPred&) = list& THEN PRINT "List is empty."
'Or you can use this method
IF PeekL&(PeekL&(list&, lh_Head&), ln_Succ&) = 0 THEN PRINT "List is empty."
Even if there is only one line of code required for this check, there is
a FUNCTION IsListEmpty& set up to do this check. You should use it to
make your programs more readable.
For example:
IF IsListEmpty&(list&) THEN PRINT "List is empty."
Back to List Functions