I want to create a tree in Fortran (90) like the one in this picture:
The idea is that I would then be able to follow a path through the tree starting from the root in the following way. At each node perform a check with the value stored there: passing the check move to the left-most child, not passing or having reached a leaf-node move the highest node that the traversal hasn't been to yet. Here is an example of a possible traversal (green indicating passing the test and red not passing):
Importantly, not every node is reached (the ones in black) which is the point of the procedure actually.
So, I think I need is a subroutine that would insert nodes in the tree, in order to build it and another that would allow me to follow paths of the kind described above.
My question is, is this possible? Does this data structure have a name?
Granted that I have virtually no experience with building data structures of this kind, Google has not been much help. An example code would be great but I would be happy to just be referred to some reading where I could learn this.