I have to classify millions of numbered triangles into different squares (suppose there are 1000 squares) by some method, but I don't know how many triangles that belong to some square before judgement. So I need 1000 linked lists so that I can store the number of relevant triangles in any length.
But it seems that I can't decalre a 1000-element head array to create 1000 linked lists in Fortran (Intel Visual Fortran 2011), and there is an error:
LoopLinkedList.for(34): error #7121: A ptr dummy may only be argument associated with a ptr, and this array element or section does not inherit the POINTER attr from its parent array. [CURRENT]
Here is code of my testing program:
module global
type node
integer i
type(node) ,pointer ::next
end type node
end module global
program LinkedList
use global
integer k
interface
subroutine insertItem(pos,item)
use global
implicit none
type(node) ,pointer ::pos,item
end subroutine insertItem
end interface
type(node), pointer::item,head(:),current(:)
allocate(head(1000))
allocate(current(1000))
head(1) = node(1,head(1))
current(1)=head(1)
do k =2,10
allocate(item)
!allocate(current%next)
item%i = k
call insertItem(current(1),item)
current(1) =item
end do
k =current(1)%i
do while(.true.)
write(*,*) current(1)%i
if(.not.associated(current(1)%next)) exit
current(1) =current(1)%next
if(current(1)%i.eq.k)exit
end do
deallocate(head)
deallocate(current)
end program LinkedList
subroutine insertItem(pos,item)
use global
implicit none
type(node) ,pointer ::item,pos
if(associated(pos%next)) then
item%next =>pos%next
pos%next=>item
end if
end subroutine insertItem