libxbps: simplify the algorithm for sorting deps in the transaction.
libxbps: simplify the algorithm for sorting deps in the transaction.

Rather than using a SIMPLEQ to copy the package dictionary and later on
adding all items into the sorted array, just add the pkg dictionary
into the sorted array directly and removing it from the unsorted array.

This reduces memory usage and greatly sorts all packages that aren't
installed automatically in the correct order in the transaction.

Also added a large comment explaining how the algorithm works and
what it is supposed to do and when.

ebfe/xbps,datenwolf/xbps,ebfe/xbps,stpx/xbps,datenwolf/xbps,ebfe/xbps,datenwolf/xbps,stpx/xbps,stpx/xbps