C Library Functions  - sort_quick_compact (3)

NAME

sort_quick_compact(3f) - [M_sort:sort:quicksort] recursive quicksort of an array (LICENSE: CC BY 3.0)

CONTENTS

Synopsis
Description
Background
Example
License

SYNOPSIS

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.

DESCRIPTION

A quicksort from high to low (descending order) using a compact recursive algorithm.

BACKGROUND

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

EXAMPLE

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_compact

Results:

    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

LICENSE

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) July 22, 2023
Generated by manServer 1.08 from d90b5a59-5d29-4764-83cd-7589e8841af8 using man macros.