Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Array of linked lists

David_Sall
Beginner
575 Views
Hi,

I am trying to create an array of linked lists and can not seem to get the proper syntax. I am trying to do the following,

do i = 1,N
call linkedlist(i,..., ptr)
tree(i) => ptr
end do

I can create a linked list, ptr, which is a derived type but want to associate it with each element of an array (pointer i assume?) so I get the following,

tree(1) => linked list from the loop when i = 1
tree(2) => linked list from the loop when i = 2
...

Could someone plase show me the syntax on how to do this? I have tried many different combinations and can not seem to get it to work!

Thank you very mcuh for your help.

Sincerely,

David
0 Kudos
3 Replies
Arjen_Markus
Honored Contributor I
575 Views
I guess you are looking for something along these lines:

type linked_list_ptr
type(linked_list_type), pointer :: ptr
end type linked_list_ptr

type(linked_list_ptr), dimension(:), allocatable :: list

list(1)%ptr => ptr_a
list(2)%ptr => ptr_b
...

Fortran does not allow an array of pointers, you must have a derived
type that intervenes.

Regards,

Arjen
0 Kudos
David_Sall
Beginner
575 Views
Hi Arjen!

That was it! Thank you very much for the help!

Sincerely,

David
0 Kudos
Arjen_Markus
Honored Contributor I
575 Views
You're welcome.

Regards,

Arjen
0 Kudos
Reply