Skip to content

Instantly share code, notes, and snippets.

@natebenes
Created April 21, 2010 19:21
Show Gist options
  • Save natebenes/374284 to your computer and use it in GitHub Desktop.
Save natebenes/374284 to your computer and use it in GitHub Desktop.
TYPE :: node
character (len=2) :: value
type(node), pointer :: left, right
END TYPE
recursive subroutine insert (t,value)
IMPLICIT NONE
TYPE(node), pointer, INTENT(IN) :: t ! really a tree
character(len=2), intent(in) :: value
! if subtree empty put number at root
IF (.not. associated(t)) then
allocate(t)
t % value = value
nullify(t%left)
nullify(t%right)
! otherwise, add to tree
ELSE IF (value < t % value) THEN
call insert (t%left, value)
ELSE
call insert (t%right, value)
END IF
END subroutine insert
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment