Skip to content

Instantly share code, notes, and snippets.

@komasaru
Created May 17, 2017 07:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save komasaru/f152528e6b35b1dc41eeea00f25708b9 to your computer and use it in GitHub Desktop.
Save komasaru/f152528e6b35b1dc41eeea00f25708b9 to your computer and use it in GitHub Desktop.
Fortran code to generate linked-list by pointer.
!****************************************************
! 整数値を格納する連結リスト
! : pointer を使用する
!
! date name version
! 2017.05.17 mk-mode.com 1.00 新規作成
!
! Copyright(C) 2017 mk-mode.com All Rights Reserved.
!****************************************************
!
program linked_list
implicit none
type node
type (node), pointer :: next_node
integer value
end type node
integer num
type (node), pointer :: first_node, new_node, p
nullify (first_node)
do
print *, '0 か正の整数を入力してください(負の整数で終了):'
read *, num
if (num < 0) exit
allocate (new_node)
new_node%next_node => first_node
new_node%value = num
first_node => new_node
end do
p => first_node
print *, "================================"
do while (associated(p))
print *, p%value
p => p%next_node
end do
end program linked_list
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment