/** * Store a newly created resource in storage. * * @return Response */ public function store() { $inputs = \Input::all(); $Tree = new Tree(); $Tree->generate($inputs); return $this->index(); }
/** * Bootstrap any application services. * * @return void */ public function boot() { \App\Attack::observe(new \App\Observers\AttackObserver()); \App\Defence::observe(new \App\Observers\DefenceObserver()); \App\Risk::observe(new \App\Observers\RiskObserver()); \App\Tree::observe(new \App\Observers\TreeObserver()); \App\User::observe(new \App\Observers\UserObserver()); }
public function testSearchThroughLotsOfLeaves() { $tree = new Tree(); $tree->insert($valueOne = 12); $tree->insert($valueTwo = 18); $tree->insert($valueThree = 24); $tree->insert($valueFour = 16); $tree->insert($valueFive = 22); $tree->insert($valueSix = 28); $this->assertEquals($tree->search($valueTwo), $tree->root); $this->assertEquals($tree->search($valueThree), $tree->root->right); $this->assertEquals($tree->search($valueOne), $tree->root->left); $this->assertEquals($tree->search($valueFive), $tree->root->right->left); $this->assertEquals($tree->search($valueSix), $tree->root->right->right); $this->assertEquals($tree->search($valueFour), $tree->root->left->right); }
/** * Store a newly created resource in storage. * * @param \App\Requests\TreeRequest $request * @return \Illuminate\Http\Response */ public function store(TreeRequest $request) { $new_tree = Tree::create($request->all()); $new_tree->syncTags($request->input('tags')); return redirect()->route('tree.show', $new_tree->id)->with('succes', 'Tree successfully created'); }
<?php include 'vendor/autoload.php'; use App\Tree; $tree = new Tree(); function printTree($node, $indent, $prefix) { $indentStr = " "; $printStr = ""; for ($i = 0; $i < $indent; $i++) { $printStr = $printStr . $indentStr; } echo $printStr . $prefix . " value: " . $node->data . "\n"; $indent++; if ($node->left) { printTree($node->left, $indent, "left: "); } if ($node->right) { printTree($node->right, $indent, "right: "); } } $tree->insert(5); printTree($tree->root, 0, "root"); echo "--------- \n"; $tree->insert(3); printTree($tree->root, 0, "root"); echo "--------- \n"; $tree->insert(4); printTree($tree->root, 0, "root");