From f1653ad88c3596faba5161b43a72f3f3467863a2 Mon Sep 17 00:00:00 2001 From: William Counts Date: Wed, 4 Apr 2007 08:49:48 +0000 Subject: [PATCH] debugged quicksort algorithm slightly (now able to do multiple identical keys) --- trunk/math.f90 | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/trunk/math.f90 b/trunk/math.f90 index 0520e0207..249c2dcf5 100644 --- a/trunk/math.f90 +++ b/trunk/math.f90 @@ -74,12 +74,12 @@ RECURSIVE SUBROUTINE qsort(a, istart, iend) implicit none - integer(pInt), dimension(*,*) :: a + integer(pInt), dimension(:,:) :: a integer(pInt) :: istart,iend,ipivot if (istart < iend) then ipivot = math_partition(a,istart, iend) - call qsort(a, istart, ipivot) + call qsort(a, istart, ipivot-1) call qsort(a, ipivot+1, iend) endif return @@ -92,13 +92,13 @@ integer(pInt) FUNCTION math_partition(a, istart, iend) implicit none - integer(pInt), dimension(*,*) :: a + integer(pInt), dimension(:,:) :: a integer(pInt) :: istart,iend,d,i,j,k,x,tmp d = size(a,1) ! number of linked data -! set the starting and ending points, and the pivot point - i = istart - j = iend +! set the starting and ending points, and the pivot point + i = istart + j = iend x = a(1,istart) do ! find the first element on the right side less than or equal to the pivot point @@ -121,7 +121,7 @@ a(k,istart) = a(k,j) a(k,j) = tmp enddo - partition = j + math_partition = j return endif enddo @@ -1150,7 +1150,6 @@ character ( len = * ) name integer(pInt) ndim integer(pInt), save :: ndim_save = 0 - integer(pInt) prime integer(pInt), save :: seed = 1 integer(pInt) value(*)