- #1
Soff
- 36
- 0
I'm trying to write a Merge Sort program with fortran 90. However, this is what I already could do:
It starts as it was planed, but after typing in the numbers, I get an error message. So, can anyone help me? Where is the bug?
Code:
program sorting
integer :: i,ialloc,error,n,d
integer, pointer :: a(:)
Print *,'How many numbers would you like to type in?'
Read(*,*)d
Print*,' Enter the values, separated by commas'
Read(*,*)(a(t),t=1, d)
!Result
call Merge(a,b,c,m,n)
print *,'Sorted list:'
write(*,*) (a(i),i=0,n-1)
print *,' '
end program sorting
!Merge Sorting of a() of dimension m and b() of dimension n
!into c() of size m+n=d
Subroutine Merge(a,b,c,m,n)
integer :: m,n,a(0:m-1),b(0:n-1),c(0:m+n-1)
integer :: i,j,k,d
i=0; j=0; k=0 !Start
do while (i<m.and.j<n)
if (a(i)<b(j)) then
c(k)=a(i)
i=i+1
else
c(k)=b(j)
j=j+1
end if
k=k+1
end do
do while (i<m) !pick up any remainder
c(k)=a(i)
k=k+1; i=i+1
end do
do while (j<n)
c(k)=b(j)
k=k+1; j=j+1
end do
return
End
It starts as it was planed, but after typing in the numbers, I get an error message. So, can anyone help me? Where is the bug?