!Description:
!  2 分木ソートのために変数を保管する
!
! Current Code Owner: sugiyama@gfd-dennou.org
!
! History: 
!   Version    Date          Comment
!   -------    ----------    -------
!   1.0        2003-01-31    新規作成
!
! Copyright (C) SUGIYAMA Ko-ichiro, 2003, All rights reserved

module interface_binsort_store
  interface
     recursive subroutine binsort_store(ptr, data)
       use prm_type, only: type_tree
       type(type_tree), pointer :: ptr
       integer, intent(in)      :: data
     end subroutine binsort_store
  end interface
end module interface_binsort_store


recursive subroutine binsort_store(ptr, data)
  use prm_type, only: type_tree

  implicit none
  type(type_tree), pointer :: ptr
  integer, intent(in)      :: data

  if (.not. associated(ptr)) then 
     allocate(ptr)
     ptr%node = data
     nullify(ptr%left)
     nullify(ptr%right)

  elseif (data < ptr%node) then 
     call binsort_store(ptr%left, data)

  elseif (data > ptr%node) then 
     call binsort_store(ptr%right, data)
  end if
  
end subroutine binsort_store

