sort_quick_compact(3f) - [M_sort:sort:quicksort] recursive quicksort of an array (LICENSE: CC BY 3.0)
Synopsis
Description
Background
Examples
License
function sort_quick_compact(data) result(sorted)
type(TYPE(KIND=**),intent(in) :: data(*) type(TYPE(KIND=**) :: sorted(size(data))where TYPE may be real, doubleprecision, integer, character or complex and of any standard kind except the character type must be the default.
A quicksort from high to low (descending order) using a compact recursive algorithm.
This compact implementation of the QuickSort algorithm is derived from an example in "Modern Fortran in Practice" by Arjen Markus
o generalized to include intrinsic types other than default REAL John S. Urban 20210110
Sample usage:
program demo_sort_quick_compact use M_sort, only : sort_quick_compact implicit none integer,parameter :: isz=10000 real :: rrin(isz) real :: rrout(isz) integer :: i write(*,*)initializing array with ,isz, random numbers CALL RANDOM_NUMBER(rrin) rrin=rrin*450000.0 write(*,*)sort real array with sort_quick_compact(3f) rrout=sort_quick_compact(rrin) write(*,*)checking do i=1,isz-1 if(rrout(i).lt.rrout(i+1))then write(*,*)Error in sorting reals, & & i,rrout(i),rrout(i+1) endif enddo write(*,*)test of sort_quick_compact(3f) complete end program demo_sort_quick_compactResults:
initializing array with 10000 random numbers sort real array with sort_quick_compact(3f) checking index of sort_quick_compact(3f) test of sort_quick_compact(3f) complete
This work is licensed under the Creative Commons Attribution 3.0 Unported License. To view a copy of this license, visit http://creativecommons.org/licenses/by/3.0/
Nemo Release 3.1 | sort_quick_compact (3) | February 23, 2025 |