stack Derived Type

type, public :: stack

the class of stack with integer elements


Contents


Type-Bound Procedures

procedure, public :: push

push an integer into a stack

  • private subroutine push(S, val)

    Arguments

    Type IntentOptional AttributesName
    class(stack) :: S
    integer, intent(in) :: val

procedure, public :: pop

pop an integer out of a stack

  • private function pop(S) result(res)

    Arguments

    Type IntentOptional AttributesName
    class(stack) :: S

    Return Value integer

procedure, public :: top

return the top of a stack

  • private function top(S) result(res)

    Arguments

    Type IntentOptional AttributesName
    class(stack) :: S

    Return Value integer

procedure, public :: num

return the number of elements in a stack

  • private function num(S) result(res)

    Arguments

    Type IntentOptional AttributesName
    class(stack) :: S

    Return Value integer

procedure, public :: clean

clean a stack

  • private subroutine clean(S)

    Arguments

    Type IntentOptional AttributesName
    class(stack) :: S

procedure, public :: read

read a stack from a file

  • private subroutine read(S, unit)

    Arguments

    Type IntentOptional AttributesName
    class(stack) :: S
    integer, intent(in) :: unit

procedure, public :: write

save a stack to a file

  • private subroutine write(S, unit)

    Arguments

    Type IntentOptional AttributesName
    class(stack) :: S
    integer, intent(in) :: unit

procedure, public :: consistent

check if a stack is consistent

  • private function consistent(S) result(res)

    Arguments

    Type IntentOptional AttributesName
    class(stack), intent(in) :: S

    Return Value logical

procedure, public :: items

public only for test, don't use

  • private function items(S) result(res)

    Arguments

    Type IntentOptional AttributesName
    class(stack), intent(in) :: S

    Return Value integer, allocatable, (:)

generic, public :: assignment(=) => copy

assignment of a stack

  • private subroutine copy(Sout, Sin)

    Arguments

    Type IntentOptional AttributesName
    class(stack), intent(inout) :: Sout
    class(stack), intent(in) :: Sin

generic, public :: operator(==) => compare

check if two stacks are equal

  • private function compare(S1, S2) result(res)

    Arguments

    Type IntentOptional AttributesName
    class(stack), intent(in) :: S1
    class(stack), intent(in) :: S2

    Return Value logical