libsim  Versione 7.2.6
Tipi di dato | Funzioni/Subroutine
Riferimenti per il modulo list_abstract

abstract class to use lists in fortran 2003. Continua...

Tipi di dato

type  list
 Abstract implementation of doubly-linked list. Continua...
 
interface  displayValues
 Print the list. Continua...
 

Funzioni/Subroutine

subroutine display (this)
 Print the list. Continua...
 
integer function countelements (this)
 count values in list Continua...
 
subroutine append (this, value)
 add class(*) to end of list Continua...
 
subroutine prepend (this, value)
 add class(*) to beginning of list Continua...
 
logical function insert (this, value, index)
 add class(*) to position in list Continua...
 
integer function currentindex (this)
 get index of currLink Continua...
 
subroutine rewind (this)
 reset list iterator to start Continua...
 
subroutine forward (this)
 reset list iterator to end Continua...
 
subroutine next (this)
 increment list iterator Continua...
 
subroutine prev (this)
 increment list iterator Continua...
 
class(*) function, pointer currentpoli (this)
 get value from currLink Continua...
 
logical function element (this)
 return .true. Continua...
 
logical function seek (this, index)
 set list iterator to index return .false. Continua...
 
logical function delete (this, index)
 delete values from list return .true. Continua...
 

Descrizione dettagliata

abstract class to use lists in fortran 2003.

Linked data structure is a data structure which consists of a set of data records (nodes) linked together and organized by references .

A doubly-linked list is a linked data structure that consists of a set of sequentially linked records called nodes. Each node contains two fields, called links, that are references to the previous and to the next node in the sequence of nodes. The beginning and ending nodes' previous and next links, respectively, point to some kind of terminator.

The program example is the better starting point:

program example_list
use kinds
implicit none
type(integerlist) :: list_int
type(reallist) :: list_real
type(characterlist) :: list_char
type(mixlist) :: list_mix
class(*),pointer :: val
integer values(10)
integer i,n
type mytype
integer :: i
real :: r
end type mytype
type(mytype) :: ir=mytype(3,6.)
type charmylen
character(len=10) :: char10
end type charmylen
type(charmylen) :: mychar
! real list
call list_real%append(3.14)
call list_real%append(6.28)
print *,"display real list"
call list_real%display()
!!$! do not work !!!
!!$! compiler bug ?
!!$ ! char fixed len (10) list
call list_char%append("hello world")
call list_char%append("bye bye baby")
print *,"display char list"
call list_char%display()
! test integer list
do i=1, 10
call list_int%append(i)
enddo
print *,"display integer list"
call list_int%display()
print *
call list_int%rewind()
i = 1
do while(list_int%element())
values(i) = list_int%current()
call list_int%next()
i = i + 1
end do
print *,"display integer vector from list"
print *, values
!more easy
values =list_int%toarray()
print *,"display integer vector from list with toarray"
print *, values
! reverse
call list_int%forward()
i = 1
do while(list_int%element())
values(i) = list_int%current()
call list_int%prev()
i = i + 1
end do
print *,"display inverse integer vector from list"
print *, values
print *,"seek return status =", list_int%seek(3)
print *,"list index 3 =", list_int%current()
! test remove
print *,"delete(5) return status =", list_int%delete(5)
print *,"display integer vector with 5 removed"
call list_int%display()
! reverse
print *,"display reverse integer vector with 5 removed"
call list_int%forward()
do while(list_int%element())
print*, "index:",list_int%currentindex()," value:",list_int%current()
call list_int%prev()
end do
print *,"delete(1) return status =", list_int%delete(1)
print *,"display integer vector with 1 removed"
call list_int%display()
n=list_int%countelements()
print *,"number of list elements=",n
print *,"delete(",n,")"
print *,"return status =", list_int%delete(n)
print *,"display integer vector with last removed"
call list_int%display()
print *,"delete return status =", list_int%delete()
print *,"display integer vector with everithings removed"
call list_int%display()
! test mix list
do i=1, 10
call list_mix%append(i)
enddo
call list_mix%append(1.23)
call list_mix%append(4d0)
call list_mix%append(ir)
! this do not work !
! compiler bug ???
! call list_mix%append("test1")
! call list_mix%append("test2")
! but this should work
mychar%char10="ciao ciao"
call list_mix%append(mychar)
print *,"display mix list"
call list_mix%display()
print *,"print mix list with cast"
call list_mix%rewind()
do while (list_mix%element())
val => list_mix%current()
select type (x => val)
type is (integer)
print *,x
type is (real)
print *,x
type is (doubleprecision)
print *,x
type is (integer(kind=int_b))
print *,x
type is (character(*))
print *,x
type is (mytype)
print *,x%i,x%r
type is (charmylen)
print *,x%char10
end select
call list_mix%next()
end do
end program example_list
Definition of constants to be used for declaring variables of a desired type.
Definition: kinds.F90:255
class to use character lists in fortran 2003 WARNING !!!! CHAR LEN IS FIXED TO listcharmaxlen.
class to use lists in fortran 2003.
class to use lists in fortran 2003.
Definition: list_mix.F03:70
class to use lists in fortran 2003.
Definition: list_real.F03:70

Generated with Doxygen.