PHP Classes

PHP Data Structure and Algorithms: Create and search data structures objects

Recommend this page to a friend!
  Info   View files Example   View files View files (26)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 46 This week: 1All time: 10,728 This week: 560Up
Version License PHP version Categories
datastructureandalgo 1.0.0MIT/X Consortium ...5Algorithms, PHP 5, Searching
Description 

Author

This package can create and search data structures objects.

It provides several classes that can store data structure information and can perform several types of algorithms that can

Currently, it provides classes that implement:

- Binary search of nodes with values linked in a tree structure

- Breadth-first search for a graph of nodes with data values with links between each other

- Manipulating and searching linked lists of nodes with the specific values

Picture of Ogbemudia Osayawe
  Performance   Level  
Name: Ogbemudia Osayawe <contact>
Classes: 8 packages by
Country: Germany Germany
Age: 40
All time rank: 2943174 in Germany Germany
Week rank: 411 Up15 in Germany Germany Up
Innovation award
Innovation award
Nominee: 5x

Example

<?php declare(strict_types=1);

use
App\BreadthFirstSearch\Graph;
use
App\BreadthFirstSearch\BreadthFirstSearch;
use
App\BreadthFirstSearch\GraphFactory;

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

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

$bfsObject = new BreadthFirstSearch(new GraphFactory());
$graph = $bfsObject->getGraph();

if (isset(
$_POST['start'], $_POST['end'])) {
   
bfs($graph, $_POST['start'], $_POST['end']);
}

function
bfs(Graph $graph, string $start, string $end): void
{
   
$result = $graph->search($start, $end);
    if (
null !== $result->getEndNode()) {
        echo
'It found ' . $result->getEndNode()->getValue() . '-';
    }
   
$path = ' Search path: ';
   
$iMax = count($result->getPath());
    foreach (
$result->getPath() as $i => $n) {
       
$path .= $n->getValue();

        if (
$i < $iMax - 1) {
           
$path .= ' --> ';
        }
    }

    echo
$path . '<br />';
}

?>

<h2>Breadth first search:</h2>
<form id="s" method="post">
    <select name="start">
        <?php if (isset($_POST['start'])): ?>
<option value="<?php echo $_POST['start']; ?>"><?php echo $_POST['start']; ?></option>
        <?php else: ?>
<option value="">Select start value</option>
        <?php endif; ?>

        <?php foreach ($graph->getNodes() as $node): ?>
<option value="<?php echo $node->getValue(); ?>"><?php echo $node->getValue(); ?></option>
        <?php endforeach; ?>
</select>

    <select name="end">
        <?php if (isset($_POST['end'])): ?>
<option value="<?php echo $_POST['end']; ?>"><?php echo $_POST['end']; ?></option>
        <?php else: ?>
<option value="">Select end value</option>
        <?php endif; ?>

        <?php foreach ($graph->getNodes() as $node): ?>
<option value="<?php echo $node->getValue(); ?>"><?php echo $node->getValue(); ?></option>
        <?php endforeach; ?>
</select>
    <input type="submit" name="Submit" value="Search">
</form>




Details

Build Status License: MIT

Data Structure and Algorithms PHP

Build the image

docker image build --tag terdia07/php-7.4 .

Run th container

docker container run -d --name dsa --publish 80:80 --mount type=bind,source="$(pwd)",target=/var/www/html terdia07/php-7.4

Enter the container

docker exec -it dsa bash

Install phpunit and setup autoloading by running:

cd /var/www/html && composer install

Run test:

./vendor/bin/phpunit tests --testdox

Visit: http://localhost





  Files folder image Files  
File Role Description
Files folder image.github (1 directory)
Files folder imagedocker (4 files)
Files folder imagesrc (3 directories)
Files folder imagetests (3 directories)
Accessible without login Plain text file bfs.php Example Example script
Accessible without login Plain text file bst.php Example Example script
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file composer.lock Data Auxiliary data
Accessible without login Plain text file data.json Data Auxiliary data
Accessible without login Plain text file Dockerfile Data Auxiliary data
Accessible without login Plain text file index.php Aux. Auxiliary script
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  .github  
File Role Description
Files folder imageworkflows (1 file)

  Files folder image Files  /  .github  /  workflows  
File Role Description
  Accessible without login Plain text file ci.yml Data Auxiliary data

  Files folder image Files  /  docker  
File Role Description
  Accessible without login Plain text file default Data Auxiliary data
  Accessible without login Plain text file init.sh Data Auxiliary data
  Accessible without login Plain text file php-fpm.conf Data Auxiliary data
  Accessible without login Plain text file supervisord.conf Data Auxiliary data

  Files folder image Files  /  src  
File Role Description
Files folder imageBinarySearchTree (2 files)
Files folder imageBreadthFirstSearch (6 files)
Files folder imageLinkedList (2 files)

  Files folder image Files  /  src  /  BinarySearchTree  
File Role Description
  Plain text file BstNode.php Class Class source
  Plain text file BsTree.php Class Class source

  Files folder image Files  /  src  /  BreadthFirstSearch  
File Role Description
  Plain text file BfsNode.php Class Class source
  Plain text file BreadthFirstSearch.php Class Class source
  Plain text file BreadthFirstSearchResult.php Class Class source
  Plain text file Graph.php Class Class source
  Plain text file GraphFactory.php Class Class source
  Plain text file GraphFactoryInterface.php Class Class source

  Files folder image Files  /  src  /  LinkedList  
File Role Description
  Plain text file LinkedList.php Class Class source
  Plain text file ListNode.php Class Class source

  Files folder image Files  /  tests  
File Role Description
Files folder imageBinarySearchTree (1 file)
Files folder imageBreadthFirstSearch (1 file)
Files folder imageLinkedList (1 file)

  Files folder image Files  /  tests  /  BinarySearchTree  
File Role Description
  Plain text file BsTreeTest.php Class Class source

  Files folder image Files  /  tests  /  BreadthFirstSearch  
File Role Description
  Plain text file BreadthFirstSearchTest.php Class Class source

  Files folder image Files  /  tests  /  LinkedList  
File Role Description
  Plain text file LinkedListTest.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:46
This week:1
All time:10,728
This week:560Up