Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module intqueue
- implicit none
- type :: queue
- integer :: n, ipop, ipush
- integer, allocatable :: a(:)
- contains
- procedure :: push
- procedure :: pop
- procedure :: empty
- final :: free
- end type queue
- interface queue
- module procedure newQueue
- end interface queue
- contains
- !########################################################
- !######################CONSTRUCTORS######################
- !########################################################
- function newQueue(n) result(res)
- implicit none
- type(queue) :: res
- integer, intent(IN) :: n
- res%n = n
- res%ipop = 1
- res%ipush = 1
- allocate(res%a(n))
- end function newQueue
- !########################################################
- !########################METHODS#########################
- !########################################################
- subroutine push(o, element)
- implicit none
- integer, intent(IN) :: element
- class(queue), intent(INOUT) :: o
- o%a(o%ipush) = element
- o%ipush = o%ipush + 1
- end subroutine push
- function pop(o) result(element)
- implicit none
- integer :: element
- class(queue), intent(INOUT) :: o
- element = o%a(o%ipop)
- o%ipop = o%ipop + 1
- o%ipush = o%ipush - 1
- end function pop
- function empty(o) result(r)
- implicit none
- class(queue), intent(INOUT) :: o
- logical :: r
- r = o%ipop-o%ipush .eq. 0
- end function empty
- subroutine free(o)
- implicit none
- type(queue), intent(INOUT) :: o
- if (allocated(o%a)) deallocate(o%a)
- end subroutine free
- end module intqueue
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement