one time used variables with name a and x to not help, assignement of i and j via loop is safe

This commit is contained in:
Martin Diehl 2017-08-12 04:51:10 +02:00
parent c531dbc022
commit 9823f5f495
1 changed files with 6 additions and 12 deletions

View File

@ -305,23 +305,17 @@ integer(pInt) function math_partition(a, istart, iend)
implicit none implicit none
integer(pInt), dimension(:,:), intent(inout) :: a integer(pInt), dimension(:,:), intent(inout) :: a
integer(pInt), intent(in) :: istart,iend integer(pInt), intent(in) :: istart,iend
integer(pInt) :: d,i,j,k,x,tmp integer(pInt) :: i,j,k,tmp
d = int(size(a,1_pInt), pInt) ! number of linked data
! set the starting and ending points, and the pivot point
i = istart
j = iend
x = a(1,istart)
do do
! find the first element on the right side less than or equal to the pivot point ! find the first element on the right side less than or equal to the pivot point
do j = j, istart, -1_pInt do j = iend, istart, -1_pInt
if (a(1,j) <= x) exit if (a(1,j) <= a(1,istart)) exit
enddo enddo
! find the first element on the left side greater than the pivot point ! find the first element on the left side greater than the pivot point
do i = i, iend do i = istart, iend
if (a(1,i) > x) exit if (a(1,i) > a(1,istart)) exit
enddo enddo
if (i < j) then ! if the indexes do not cross, exchange values if (i < j) then ! if the indexes do not cross, exchange values
do k = 1_pInt,d do k = 1_pInt,d
@ -330,7 +324,7 @@ integer(pInt) function math_partition(a, istart, iend)
a(k,j) = tmp a(k,j) = tmp
enddo enddo
else ! if they do cross, exchange left value with pivot and return with the partition index else ! if they do cross, exchange left value with pivot and return with the partition index
do k = 1_pInt,d do k = 1_pInt, int(size(a,1_pInt), pInt) ! number of linked data
tmp = a(k,istart) tmp = a(k,istart)
a(k,istart) = a(k,j) a(k,istart) = a(k,j)
a(k,j) = tmp a(k,j) = tmp