<?php
// require_once './src/btree.php';
// require_once './src/tree.php';
// require_once './src/node.php';
// require_once './src/nullnode.php';
// require_once './src/binarynode.php';
require_once('./Autoloader_src.php');
highlight_string('<?php
$btree= new Btree(new BinaryNode(4));
echo \'<pre>\';
$btree->getRoot()
->addChildren(array(\'left\'=>new notnullnode(\'son\')))
->getLeftChild()
->addChildren(
array(
\'left\'=>new notnullnode(\'grandson\'),
\'right\'=>new notnullnode(\'c16\')
)
)
->getParent()
->replaceChild(new notnullnode(\'brotherofson\'),\'right\')
->getRightChild()
->addChildren(
array(
\'left\'=>new notnullnode(\'grandson1\'),
\'right\'=>new notnullnode(\'c17\')
)
)
->swapChildren()
->getParent()
->swapChildren()
->getLeftChild()
->getLeftChild()
->addChildren(
array(
\'left\'=>new notnullnode(\'doublegrandson\'),
\'right\'=>new notnullnode(\'c18\')
)
);
var_dump(count($btree));//return the number of true node
var_dump($btree->toArray());//return a representative array of a tree;
?>');
$btree= new Btree(new BinaryNode(4));
echo '<pre>';
$btree->getRoot()
->addChildren(array('left'=>new notnullnode('son')))
->getLeftChild()
->addChildren(
array(
'left'=>new notnullnode('grandson'),
'right'=>new notnullnode('c16')
)
)
->getParent()
->replaceChild(new notnullnode('brotherofson'),'right')
->getRightChild()
->addChildren(
array(
'left'=>new notnullnode('grandson1'),
'right'=>new notnullnode('c17')
)
)
->swapChildren()
->getParent()
->swapChildren()
->getLeftChild()
->getLeftChild()
->addChildren(
array(
'left'=>new notnullnode('doublegrandson'),
'right'=>new notnullnode('c18')
)
);
var_dump(count($btree));//return the number of true node
var_dump($btree->toArray());//return a representative array of a tree;
highlight_string('<?php /*can use square bracket to progressively access the tree like an array*/
print_r($btree->getRoot()[\'left\'][\'lEft\'][\'rigHt\']);
print_r($btree[\'top\'][\'left\'][\'lEft\'][\'left\']);
$btree->getRoot()[\'left\'][\'lEft\'][\'left\'][\'value\']=\'c19\';
echo $btree[\'top\'][\'left\'][\'lEft\'][\'left\'][\'parentId\'].\'<br>\';//same as:
echo $btree[\'root\'][\'left\'][\'lEft\'][\'left\'][\'dad\'].\'<br>\';
?>');
/**/
print_r($btree->getRoot()['left']['lEft']['rigHt']);
print_r($btree['top']['left']['lEft']['left']);
$btree->getRoot()['left']['lEft']['left']['value']='c19';
echo $btree['top']['left']['lEft']['left']['parentId'].'<br>';
echo $btree['root']['left']['lEft']['left']['dad'].'<br>';
highlight_string('<?php
print_r($btree->getRoot()->getChildren()[\'left\']->getChildren()[\'left\']->getGrandPa());//same as
print_r($btree->getRoot()->getGrandSons()[\'left\'][\'left\']->getGrandPa());
?>');
print_r($btree->getRoot()->getChildren()['left']->getChildren()['left']->getGrandPa());
print_r($btree->getRoot()->getGrandSons()['left']['left']->getGrandPa());
// var_dump(eval('return '.$btree->export(true).';'));
// var_dump(isset($btree->getRoot()['left']));
// unset($btree->getRoot()['left']);
// var_dump(isset($btree->getRoot()['left']));
highlight_string('<?php
var_dump(isset($btree->getRoot()[\'left\'][\'children\']));
var_dump($btree->getRoot()[\'left\'][\'left\'][\'uncle\'][\'brother\']);
?>');
var_dump(isset($btree->getRoot()['left']['children']));
var_dump($btree->getRoot()['left']['left']['uncle']['brother']);
highlight_string('<?php
$x=new Stemnode(\'tada\');
$x->addchild($y=new stemnode(1));
$x->addchild(new stemnode(1));
$x->addchild(new stemnode(1));
$y->addchild(new stemnode(1));
$y[0]->addchild($nt=new notnullnode(6));
var_dump($x[0][0][\'parentId\']);
var_dump(eval(\'return \'.$x->export(true).\';\'));
var_dump($t=new Tree($x));
$nt->addChildren(array(\'left\'=>new BinaryNode(\'fortestpurpose\')));
var_dump($t[\'top\'][0][0][0][\'left\']);
echo count($btree);
echo \'<br>\';
echo count($t);
var_dump($t[\'top\'][\'grandsons\']);
echo \'</pre>\';
foreach($t[\'top\'] as $child){
echo $child.\'<br>\';
}
$t[\'top\']->rewind();
$t[\'top\']->next();
echo \'<br>\';
echo \'<br>\';
echo \'<br>\';
var_dump($t[\'top\']->prev());
?>');
$x=new Stemnode('tada');
$x->addchild($y=new stemnode(1));
$x->addchild(new stemnode(1));
$x->addchild(new stemnode(1));
$y->addchild(new stemnode(1));
$y[0]->addchild($nt=new notnullnode(6));
var_dump($x[0][0]['parentId']);
var_dump(eval('return '.$x->export(true).';'));
var_dump($t=new Tree($x));
$nt->addChildren(array('left'=>new BinaryNode('fortestpurpose')));
var_dump($t['top'][0][0][0]['left']);
echo count($btree);
echo '<br>';
echo count($t);
var_dump($t['top']['grandsons']);
echo '</pre>';
foreach($t['top'] as $child){
echo $child.'<br>';
}
$t['top']->rewind();
$t['top']->next();
echo '<br>';
echo '<br>';
echo '<br>';
var_dump($t['top']->prev());
?>
|