-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlinkedtest.f90
134 lines (109 loc) · 3.14 KB
/
linkedtest.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
! A simple generic linked list test program
module data
implicit none
private
public :: data_t
public :: data_ptr
! Data is stored in data_t
type :: data_t
real :: x
end type data_t
! A trick to allow us to store pointers in the list
type :: data_ptr
type(data_t), pointer :: p
end type data_ptr
end module data
program list_test
use linkedlist
use data
implicit none
integer :: cont
type(list_t), pointer :: ll => null(), node
type(data_t), target :: dat_a
type(data_t), target :: dat_b
type(data_ptr) :: ptr
print*, "enter"
read(*,*)
do cont = 1, 100000
! Initialize two data objects
dat_a%x = 17.5
dat_b%x = 3.0
! Initialize the list with dat_a
allocate(ptr%p)
ptr%p%x = 17.5 ! dat_a%x
call list_init(ll, DATA=transfer(ptr, list_data))
print *, 'Initializing list with data:', ptr%p
! deallocate(ptr%p)
allocate(ptr%p)
! Insert dat_b into the list
ptr%p%x = 3.0 ! dat_b%x
call list_insert(ll, DATA=transfer(ptr, list_data))
print *, 'Inserting node with data:', ptr%p
! deallocate(ptr%p)
allocate(ptr%p)
! Insert dat_b into the list
ptr%p%x = 40.0 ! dat_b%x
call list_insert(ll, DATA=transfer(ptr, list_data))
print *, 'Inserting node with data:', ptr%p
! deallocate(ptr%p)
dat_a%x = 0
dat_b%x = 0
! Get the head node
ptr = transfer(list_get(ll), ptr)
print *, 'Head node data:', ptr%p
deallocate(ptr%p)
! Get the next node
node => list_next(ll)
ptr = transfer(list_get(list_next(ll)), ptr)
print *, 'Second node data:', ptr%p
deallocate(ptr%p)
! Get the next node
node => list_next(node)
ptr = transfer(list_get(node), ptr)
print *, 'Third node data:', ptr%p
deallocate(ptr%p)
! Free the list
! print*, "blablabla"
! ! Get the head node
! ptr = transfer(list_get(ll), ptr)
! print *, 'Head node data:', ptr%p
! deallocate(ptr%p)
! ! Get the next node
! node => list_next(ll)
! ptr = transfer(list_get(list_next(ll)), ptr)
! print *, 'Second node data:', ptr%p
! deallocate(ptr%p)
! ! Get the next node
! node => list_next(node)
! ptr = transfer(list_get(node), ptr)
! print *, 'Third node data:', ptr%p
! deallocate(ptr%p)
! ! Free the list
call list_free(ll)
end do
print*, "enter"
read(*,*)
! print*, "enter"
! read(*,*)
! do cont = 1, 100000
! ! Initialize two data objects
! dat_a%x = 17.5
! dat_b%x = 3.0
! ! Initialize the list with dat_a
! ptr%p => dat_a
! call list_init(ll, DATA=transfer(ptr, list_data))
! print *, 'Initializing list with data:', ptr%p
! ! Insert dat_b into the list
! ptr%p => dat_b
! call list_insert(ll, DATA=transfer(ptr, list_data))
! print *, 'Inserting node with data:', ptr%p
! ! Get the head node
! ptr = transfer(list_get(ll), ptr)
! print *, 'Head node data:', ptr%p
! ! Get the next node
! ptr = transfer(list_get(list_next(ll)), ptr)
! print *, 'Second node data:', ptr%p
! ! Free the list
! call list_free(ll)
! end do
end program list_test