next up previous
Next: The Partition Concept Up: A Quick Sort Previous: A Quick Sort

The Control Algorithm as Content

Consider now, the implementation of the Recursive_Quick_Sort content, requiring a Partition algorithm as contentual context.

 
generic

with Procedure Partition(Els: in out El_Sequence;

Low,High: in El_Sequence_Ind;

Split: out El_Sequence_Ind);

procedure Recursive_Quick_Sort (Els: in out El_Sequence;

Low,High: in El_Sequence_Ind) implements Sort as

C: El_Sequence_Ind;

begin

if Low < High then

Partition(Els,Low,High,C);

Recursive_Quick_Sort(Els,Low,El_Sequence_Ind'Pred(C));

Recursive_Quick_Sort(Els,El_Sequence_Ind'Succ(C),High);

end if;

end Recursive_Quick_Sort;

Note that the concern encapsulated here is essentially control. The actual partitioning is performed in Partition. Because of this, the control algorithm and both the Element and El_Sequence conceptual context are only "weakly" interconnected. That is, the control algorithm only passes Els as a parameter and does not use the El_Sequence operations provided by the Sort concept. Furthermore, the algorithm makes no reference to operations on Element objects.



Larry Latour
Fri Feb 23 23:01:25 EST 1996