debugged quicksort algorithm slightly (now able to do multiple identical keys)

This commit is contained in:
William Counts 2007-04-04 08:49:48 +00:00
parent f055a7b037
commit f1653ad88c
1 changed files with 7 additions and 8 deletions

View File

@ -74,12 +74,12 @@
RECURSIVE SUBROUTINE qsort(a, istart, iend) RECURSIVE SUBROUTINE qsort(a, istart, iend)
implicit none implicit none
integer(pInt), dimension(*,*) :: a integer(pInt), dimension(:,:) :: a
integer(pInt) :: istart,iend,ipivot integer(pInt) :: istart,iend,ipivot
if (istart < iend) then if (istart < iend) then
ipivot = math_partition(a,istart, iend) ipivot = math_partition(a,istart, iend)
call qsort(a, istart, ipivot) call qsort(a, istart, ipivot-1)
call qsort(a, ipivot+1, iend) call qsort(a, ipivot+1, iend)
endif endif
return return
@ -92,7 +92,7 @@
integer(pInt) FUNCTION math_partition(a, istart, iend) integer(pInt) FUNCTION math_partition(a, istart, iend)
implicit none implicit none
integer(pInt), dimension(*,*) :: a integer(pInt), dimension(:,:) :: a
integer(pInt) :: istart,iend,d,i,j,k,x,tmp integer(pInt) :: istart,iend,d,i,j,k,x,tmp
d = size(a,1) ! number of linked data d = size(a,1) ! number of linked data
@ -121,7 +121,7 @@
a(k,istart) = a(k,j) a(k,istart) = a(k,j)
a(k,j) = tmp a(k,j) = tmp
enddo enddo
partition = j math_partition = j
return return
endif endif
enddo enddo
@ -1150,7 +1150,6 @@
character ( len = * ) name character ( len = * ) name
integer(pInt) ndim integer(pInt) ndim
integer(pInt), save :: ndim_save = 0 integer(pInt), save :: ndim_save = 0
integer(pInt) prime
integer(pInt), save :: seed = 1 integer(pInt), save :: seed = 1
integer(pInt) value(*) integer(pInt) value(*)