program main character(len=100000)::str integer::len integer,allocatable::a(:),b(:) character*32::cformat='( i1)' read *, str len = LEN_TRIM(str) write(cformat(2:7),'(i0)'),len allocate(a(len)) read(str,cformat) a b = qsortr(a) write(*,cformat)b contains recursive function qsortr(x) result(y) integer*4,intent(in) ::x(:) integer*4,allocatable::y(:) integer*4::pivot,total total = size(x) if (total <=1) then y = x else pivot = x(total/2) y = [qsortr(pack(x, x .gt. pivot)), & pack(x, x .eq. pivot), & qsortr(pack(x, x .lt. pivot))] endif end function qsortr end program main