fork download
  1. program quick_sort
  2. implicit none
  3. real :: x(100)
  4. call random_seed()
  5. call random_number(x)
  6. print '(10f8.5)', qsort(x)
  7. stop
  8. contains
  9. recursive function qsort(a) result(res)
  10. real, intent(in) :: a(:)
  11. real :: res(size(a))
  12. if (size(a) < 2) then
  13. res = a
  14. else
  15. res = (/ qsort( pack(a(2:), a(2:) < a(2)) ), a(1), qsort( pack(a(2:), a(2:) >= a(2)) ) /)
  16. end if
  17. return
  18. end function qsort
  19. end program quick_sort
Success #stdin #stdout 0.01s 2624KB
stdin
Standard input is empty
stdout
 0.07375 0.01515 0.13316 0.04815 0.09327 0.06171 0.10057 0.07656 0.11421 0.10125
 0.11424 0.14784 0.11582 0.13753 0.10038 0.15072 0.01611 0.20687 0.21596 0.34224
 0.26158 0.25680 0.30381 0.31846 0.21795 0.32299 0.33002 0.33932 0.00536 0.37480
 0.37558 0.34708 0.40129 0.40246 0.42151 0.38677 0.44548 0.45688 0.48038 0.36739
 0.50368 0.49760 0.51997 0.54927 0.48064 0.55290 0.55087 0.55401 0.55859 0.99756
 0.59769 0.58740 0.59682 0.64641 0.59840 0.60569 0.61231 0.61437 0.62088 0.66193
 0.65792 0.71905 0.65823 0.66966 0.66494 0.67453 0.70618 0.65905 0.72886 0.73402
 0.73113 0.74631 0.75176 0.67298 0.75545 0.77360 0.81381 0.79292 0.76961 0.82062
 0.65085 0.88588 0.85569 0.89733 0.74793 0.90052 0.90192 0.94685 0.92863 0.95358
 0.94709 0.95376 0.56682 0.96592 0.97776 0.96854 0.99792 0.99039 0.97866 0.99914