procedure QSort(Items: in out ItemVec; L,R: in Integer) is
I: Integer := L;
J: Integer := R;
X: constant Item := Items((L+R)/2);
Y: Item;
begin
loop
while Items(I)>X loop I:=I+1; end loop;
while X>Items(J) loop J:=J-1; end loop;
if I <= J then
Y:=Items(I); Items(I):=Items(J); Items(J):=Y;
I:=I+1; J:=J-1;
end if;
exit when I>J;
end loop;
if L<J then QSort(Items,L,J); end if;
if I<R then QSort(Items,I,R); end if;
end QSort;