all tasks

This commit is contained in:
Ingy döt Net 2013-04-11 01:07:29 -07:00
parent b83f433714
commit 68f8f3e56b
14735 changed files with 178959 additions and 0 deletions

View file

@ -0,0 +1,39 @@
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
forall(i=tmin:tmax)
cnt(i) = count(array == i)
end forall
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

View file

@ -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