-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmylinkedlist_printRecursive.f90
59 lines (49 loc) · 1.06 KB
/
mylinkedlist_printRecursive.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
program ketoprak
use salak
implicit none
type(node), pointer::ll
nullify(head)
call insertn(9)
call insertn(15)
call insertn(3)
call insertn(17)
! print *, head%data, head%next%data, head%next%next%data
call printn(head)
!call sizen()
stop
contains
subroutine insertn(idat)
implicit none
integer idat
type(node), pointer::tmp
allocate(tmp); tmp%data = idat; nullify(tmp%next)
tmp%next => head; head => tmp
return
end subroutine insertn
recursive subroutine printn(tmp)
implicit none
type(node), pointer::tmp
if(.not.associated(tmp)) return
print*, tmp%data
call printn(tmp%next)
return
end subroutine printn
subroutine sizen()
implicit none
integer n
type(node), pointer::tmp
tmp => head
if(.not.associated(tmp)) then
print *, 'no linked-list'
return
else
n = 0
do while(associated(tmp))
n = n+1
tmp => tmp%next
end do
end if
print *, n
return
end subroutine sizen
end program ketoprak