Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -0,0 +1,43 @@
|
|||
module CountingSort
|
||||
implicit none
|
||||
|
||||
interface counting_sort
|
||||
module procedure counting_sort_mm, counting_sort_a
|
||||
end interface
|
||||
|
||||
contains
|
||||
|
||||
subroutine counting_sort_a(array)
|
||||
integer, dimension(:), intent(inout) :: array
|
||||
|
||||
call counting_sort_mm(array, minval(array), maxval(array))
|
||||
|
||||
end subroutine counting_sort_a
|
||||
|
||||
subroutine counting_sort_mm(array, tmin, tmax)
|
||||
integer, dimension(:), intent(inout) :: array
|
||||
integer, intent(in) :: tmin, tmax
|
||||
|
||||
integer, dimension(tmin:tmax) :: cnt
|
||||
integer :: i, z
|
||||
|
||||
cnt = 0 ! Initialize to zero to prevent false counts
|
||||
FORALL (I=1:size(array)) ! Not sure that this gives any benefit over a DO loop.
|
||||
cnt(array(i)) = cnt(array(i))+1
|
||||
END FORALL
|
||||
!
|
||||
! ok - cnt contains the frequency of every value
|
||||
! let's unwind them into the original array
|
||||
!
|
||||
z = 1
|
||||
do i = tmin, tmax
|
||||
do while ( cnt(i) > 0 )
|
||||
array(z) = i
|
||||
z = z + 1
|
||||
cnt(i) = cnt(i) - 1
|
||||
end do
|
||||
end do
|
||||
|
||||
end subroutine counting_sort_mm
|
||||
|
||||
end module CountingSort
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
program test
|
||||
use CountingSort
|
||||
implicit none
|
||||
|
||||
integer, parameter :: n = 100, max_age = 140
|
||||
|
||||
real, dimension(n) :: t
|
||||
integer, dimension(n) :: ages
|
||||
|
||||
call random_number(t)
|
||||
ages = floor(t * max_age)
|
||||
|
||||
call counting_sort(ages, 0, max_age)
|
||||
|
||||
write(*,'(I4)') ages
|
||||
|
||||
end program test
|
||||
Loading…
Add table
Add a link
Reference in a new issue