Created
April 21, 2010 19:21
-
-
Save natebenes/374284 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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