Skip to content

Instantly share code, notes, and snippets.

@stuartgibson
Created December 4, 2012 13:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stuartgibson/4204035 to your computer and use it in GitHub Desktop.
Save stuartgibson/4204035 to your computer and use it in GitHub Desktop.
<?php
echo '<pre>';
class node
{
var $name = NULL;
var $left = NULL;
var $right = NULL;
var $content = NULL;
public function __construct( $name )
{
$this->name = $name;
}
}
$food = new node('Food');
$fruit = new node('Fruit');
$meat = new node('Meat');
$red = new node('Red');
$yellow = new node('Yellow');
$strawberry = new node('Strawberry');
$cherry = new node('Cherry');
$banana = new node('Banana');
$lemon = new node('Lemon');
$orange = new node('Orange');
$tangerine = new node('Tangerine');
$beef = new node('Beef');
$pork = new node('Pork');
$maraschino = new node('Maraschino');
$meat->content = array($beef, $pork);
$cherry->content = array($maraschino);
$red->content = array($strawberry, $cherry);
$yellow->content = array($banana, $lemon);
$orange->content = array($tangerine);
$fruit->content = array($red, $yellow, $orange);
$food->content = array($fruit, $meat);
function build_it( $pages, $left = 1, $right = null)
{
if( is_array( $pages->content ) )
{
$pages->left = $left;
foreach( $pages->content as $page )
{
$left++;
$right = build_it( &$page, &$left);
}
$pages->right = ++$right;
}
else
{
$pages->left = $left;
$pages->right = ++$left;
return $pages->right;
}
$left++;
return $right;
}
build_it( &$food );
print_r($food);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment