Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module intqueue
- implicit none
- type :: queue
- integer :: n, i
- 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%i = 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%i) = element
- o%i = o%i + 1
- end subroutine push
- function pop(o) result(element)
- implicit none
- integer :: element, i
- class(queue), intent(INOUT) :: o
- element = o%a(1)
- do i=1,size(o%a)-1
- o%a(i) = o%a(i+1)
- enddo
- o%i = o%i - 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