sort_quick_compact Interface

public interface sort_quick_compact

Contents


Module Procedures

private recursive function sort_quick_compact_integer_int8(data) result(sorted)

NAME

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

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/

Arguments

Type IntentOptional Attributes Name
integer(kind=int8), intent(in) :: data(:)

Return Value integer(kind=int8), (1:size(data))

private recursive function sort_quick_compact_integer_int16(data) result(sorted)

Arguments

Type IntentOptional Attributes Name
integer(kind=int16), intent(in) :: data(:)

Return Value integer(kind=int16), (1:size(data))

private recursive function sort_quick_compact_integer_int32(data) result(sorted)

Arguments

Type IntentOptional Attributes Name
integer(kind=int32), intent(in) :: data(:)

Return Value integer(kind=int32), (1:size(data))

private recursive function sort_quick_compact_integer_int64(data) result(sorted)

Arguments

Type IntentOptional Attributes Name
integer(kind=int64), intent(in) :: data(:)

Return Value integer(kind=int64), (1:size(data))

private recursive function sort_quick_compact_real_real32(data) result(sorted)

Arguments

Type IntentOptional Attributes Name
real(kind=real32), intent(in) :: data(:)

Return Value real(kind=real32), (1:size(data))

private recursive function sort_quick_compact_real_real64(data) result(sorted)

Arguments

Type IntentOptional Attributes Name
real(kind=real64), intent(in) :: data(:)

Return Value real(kind=real64), (1:size(data))

private recursive function sort_quick_compact_real_real128(data) result(sorted)

Arguments

Type IntentOptional Attributes Name
real(kind=real128), intent(in) :: data(:)

Return Value real(kind=real128), (1:size(data))

private recursive function sort_quick_compact_complex_real32(data) result(sorted)

Arguments

Type IntentOptional Attributes Name
complex(kind=real32), intent(in) :: data(:)

Return Value complex(kind=real32), (1:size(data))

private recursive function sort_quick_compact_complex_real64(data) result(sorted)

Arguments

Type IntentOptional Attributes Name
complex(kind=real64), intent(in) :: data(:)

Return Value complex(kind=real64), (1:size(data))

private recursive function sort_quick_compact_character_ascii(data) result(sorted)

Arguments

Type IntentOptional Attributes Name
character(kind=ascii, len=*), intent(in) :: data(:)

Return Value character(kind=ascii, len=len), (1:size(data))