FICO Xpress Optimization Examples Repository
FICO Optimization Community FICO Xpress Optimization Home
Back to examples browserPrevious exampleNext example

Defining a package to handle binary trees

  • definition of subroutines (function, procedure)
  • data structures 'list' and 'record'
  • type definitions
The package 'bintree' defines the new types 'tree' (to represent a binary tree data structure) and 'node' (a tree node, building blocks of trees storing the actual data) for the Mosel language and also a set of subroutines for working with trees, such as inserting a value into a tree, locating a value, getting the tree size, printing out a tree, and converting a tree to a list.

The model file 'exbtree.mos' shows how to create a tree and work with it using the functionality of this package. To run this example, you first need to compile the package (resulting in the BIM file 'bintree.bim'). You may then execute the example in the same directory that contains this BIM file.

Source Files


   Mosel Example Problems

   file exbtree.mos
   Example of use lists and of the 'bintree' package

   -- Note: The package 'bintree' (file bintree.mos)  
      needs to be compiled before executing this model --

   (c) 2008 Fair Isaac Corporation
       author: Y. Colombani, 2006
model exbtree
uses ':bintree.bim'

 allvals:list of real

until arbre.size = 10

write("Values in the binary tree:"); show(arbre)

writeln("The smallest value:",allvals.first)
writeln("The biggest value:",allvals.last)
writeln("The 5 first entries:",splithead(allvals,5))
writeln("Remaining after split:",allvals)


Back to examples browserPrevious exampleNext example