Contents    Page-10    Prev    Next    Page+10    Index   

On Not Dropping the Ball

llmergesort is a destructive sorting function that will change the order, but not the location or contents, of list elements.

Suppose that lst is (b c a) and we perform llmergesort(lst). If we now print out lst, it looks like (b c). Has part of the list been lost?

What we need to do is to perform an assignment to save the result of the sort.


   lst = llmergesort(lst);
This will save the result of sorting. We don't want the old value of lst any longer since it now points into the middle of the sorted list.

Rule: Save the result of a function by doing an assignment to a variable. If the function is destructive, use the same variable name as the original, since what it pointed to before is no longer meaningful.