package body SORT is ----------------------- -- Local Subprograms -- ----------------------- --------------- -- SORT -- --------------- -- Quadratic sort algorithm procedure SORT ( A: in out TDA_TYPE ) is N: KEY_TYPE; BIGGEST: KEY_TYPE; begin N:= SIZE(A); for I in reverse INTEGER(INITIAL_INDEX)..INTEGER(N) loop -- Initially, The biggest will be the first position BIGGEST:= INITIAL_INDEX; -- In this loop we search for the position of the biggest element for J in INTEGER(INITIAL_INDEX)..I loop -- biggest will be a element wich is greater or equal -- than the current biggest if GREATEREQUAL( A, KEY_TYPE(J), BIGGEST ) then BIGGEST:= KEY_TYPE( J); end if; end loop; if ( KEY_TYPE(I) /= BIGGEST) then -- swap the biggest element with position N SWAP( A, KEY_TYPE(I), BIGGEST ); end if; end loop; end SORT; end SORT;