포트란 linked list
아래의 코드에서 linked list결과가
1.0
2.0
이렇게 나와야 하는데
0.0
1.0
2.0
이렇게 나오네요. 어디서 0.0의 값이 끼어들었는지 아무리봐도
모르겠습니다.
도와주세요. ㅠ.ㅠ
C=========================================
module list
******************************************
type :: list_node
type (list_node), pointer :: p
real(8) :: data
end type list_node
******************************************
end module list
subroutine list_test(n,head)
use list
type (list_node), pointer :: tail, head, ptr
integer :: i, n
integer :: istatus
n = 2
do i = 1, n
if (i.eq.1) then
allocate(head,stat=istatus)
tail => head
else
allocate(tail%p,stat=istatus)
tail => tail%p
end if
tail%data = i
nullify(tail%p)
end do
end subroutine list_test
******** MAIN PROGRAM ******
program test
use list
type (list_node), pointer :: head, ptr
integer :: n
allocate(head,stat=istatus) ! important
call list_test(n,head)
ptr => head
istatus = associated(ptr)
do while ( associated(ptr) )
print *, 'data=', ptr%data
ptr => ptr%p
end do
end program test
댓글 달기