TopoSort.Mesa
Last tweaked by Mike Spreitzer on May 18, 1988 9:57:29 am PDT
Christian Jacobi, April 7, 1992 5:15 pm PDT
DIRECTORY Basics;
TopoSort: CEDAR DEFINITIONS = {
PartialComparison: TYPE ~ Basics.PartialComparison --{less, equal, greater, incomparable}--;
Handle: TYPE ~ REF ANY;
A handle on an abstract list node.
ListSort: PROC [
alpha, omega: Handle,
GetLink: PROC [Handle] RETURNS [Handle],
SetLink: PROC [from, to: Handle],
Compare: PROC [Handle, Handle] RETURNS [PartialComparison]
];
Sorts a list, destructively, via a merge-sorting technique. If the partial order is in fact total, does almost the same thing as List.Sort (differences may arise when there are equal elements).
I'm not guaranteeing whether the sort is stable.
I'm not guaranteeing whether the sort leaves equal elements consecutive.
The list is represented abstractly, and can be singly or doubly linked. The GetLink procedure gets the `forward' link from a list node. The SetLink procedure is called to change the links so as to make one node immediately follow another. alpha is the node before the first, and omega is the node after the last. It's OK to use the same Handle for alpha and omega, there's no variable that might take on either value.
}.