PHP Classes

File: bst.php

Recommend this page to a friend!
  Classes of Ogbemudia Osayawe   PHP Data Structure and Algorithms   bst.php   Download  
File: bst.php
Role: Example script
Content type: text/plain
Description: Example script
Class: PHP Data Structure and Algorithms
Create and search data structures objects
Author: By
Last change:
Date: 2 years ago
Size: 762 bytes
 

Contents

Class file image Download
<?php declare(strict_types=1);

use
App\BinarySearchTree\BsTree;

require_once
__DIR__ . '/vendor/autoload.php';

ini_set('display_errors', '1');
error_reporting(E_ALL);

$tree = new BsTree();
/* for ($i = 0; $i < 10; $i++) {
    $tree->addValue(random_int(0, 100));
}*/
$tree->addValue(7);
$tree->addValue(9);
$tree->addValue(3);
$tree->addValue(1);
$tree->addValue(5);
$tree->addValue(8);

echo
'<br /> Ordered list: ';
var_dump($tree->traverse());

echo
'<br /> Search result: ';
$result = $tree->search(5);
echo
$result->getValue();

echo
'<br /> Reversed list: ';
$tree->reverse();
var_dump($tree->traverse());

$tree->reverse();
echo
'<br /> Reset: ';
$tree->traverse();
echo
'<br /> Search : ';
$result = $tree->search(3);
echo
$result->getValue();