-
Notifications
You must be signed in to change notification settings - Fork 184
/
Copy pathexample_linked_insert.f90
59 lines (44 loc) · 1.18 KB
/
example_linked_insert.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
! example_insert.f90 --
! Demonstrate the insert method
!
program example_insert
use stdlib_linked_list
implicit none
type(linked_list_type) :: list
!
! Add a few elements
!
call list%insert( "String element", 1 )
call list%insert( 2, 2 )
call list%insert( 3.3, 3 )
call print_list( list )
!
! Now insert an element in the middle
!
call list%insert( "Another string", 2 )
!
! Print the list
!
write(*,*) 'New list:'
call print_list( list )
contains
!include 'linked_list_aux.inc'
subroutine print_list( list )
type(linked_list_type), intent(in) :: list
integer :: i
class(*), pointer :: list_item
do i = 1,list%size()
list_item => list%get(i)
select type( item => list_item )
type is (integer)
write(*,*) i, item, ' (integer)'
type is (real)
write(*,*) i, item, ' (real)'
type is (character(*))
write(*,*) i, ' >', item, '< (string)'
class default
write(*,*) i, ' (type unknown)'
end select
enddo
end subroutine print_list
end program example_insert