Replaced sorting method which resulted in broken deletion algorithm

This commit is contained in:
Alex Selimov 2020-05-18 10:38:01 -04:00
parent 4f79085956
commit 9ccc5f1caf
3 changed files with 895 additions and 71 deletions

View file

@ -173,52 +173,6 @@ module subroutines
end subroutine parse_ori_vec
subroutine heapsort(a)
integer, intent(in out) :: a(0:)
integer :: start, n, bottom
real :: temp
n = size(a)
do start = (n - 2) / 2, 0, -1
call siftdown(a, start, n);
end do
do bottom = n - 1, 1, -1
temp = a(0)
a(0) = a(bottom)
a(bottom) = temp;
call siftdown(a, 0, bottom)
end do
end subroutine heapsort
subroutine siftdown(a, start, bottom)
integer, intent(in out) :: a(0:)
integer, intent(in) :: start, bottom
integer :: child, root
real :: temp
root = start
do while(root*2 + 1 < bottom)
child = root * 2 + 1
if (child + 1 < bottom) then
if (a(child) < a(child+1)) child = child + 1
end if
if (a(root) < a(child)) then
temp = a(child)
a(child) = a (root)
a(root) = temp
root = child
else
return
end if
end do
end subroutine siftdown
subroutine apply_periodic(r)
@ -344,4 +298,4 @@ module subroutines
return
end subroutine check_right_ortho
end module subroutines
end module subroutines