[UP]


Manual Reference Pages  - tree_insert (3)

NAME

tree_insert(3f) - [M_sort] sort a number of integers by building a tree, sorted in infix order

CONTENTS

Synopsis
Description
Author
Example

SYNOPSIS

subroutine tree_insert(t,number)

   type(tree_node), pointer :: t
   integer             :: number

DESCRIPTION

Sorts a number of integers by building a tree, sorted in infix order. This sort has expected behavior n log n, but worst case (input is sorted) n ** 2.

AUTHOR

Copyright (c) 1990 by Walter S. Brainerd, Charles H. Goldberg, and Jeanne C. Adams. This code may be copied and used without restriction as long as this notice is retained.

EXAMPLE

sample program

   program tree_sort
   use M_sort, only : tree_node, tree_insert, tree_print
   implicit none
   type(tree_node), pointer :: t     ! A tree
   integer             :: number
   integer             :: ios
   nullify(t)                        ! Start with empty tree
   infinite: do
      read (*,*,iostat=ios) number
      if(ios.ne.0)exit infinite
      call tree_insert(t,number)     ! Put next number in tree
   enddo infinite
   call tree_print(t)                ! Print nodes of tree in infix order
   end program tree_sort


tree_insert (3) October 17, 2020
Generated by manServer 1.08 from 16fbc78a-31bc-4591-a63d-fa48bc8cc059 using man macros.