PHP code example of adrianschubek / structures

1. Go to this page and download the library: Download adrianschubek/structures library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

adrianschubek / structures example snippets


use adrianschubek\Structures\Linear\Queue;

$queue = new Queue();
$queue->enqueue("Berlin");
$queue->enqueue("Munich");
$queue->enqueue("Cologne");

$queue->dequeue();

$arr = $queue->toArray();
// ==> ["Munich", "Cologne"]

use adrianschubek\Structures\Linear\DynamicList;

$list = new DynamicList();

$list->append("Berlin");
$list->append("Munich");
$list->append("Cologne");

$list2 = new DynamicList();
$list2->append("Düsseldorf");
$list2->append("Essen");

$list->concat($list2);
// ==> ["Berlin", "Munich", "Cologne", "Düsseldorf", "Essen"]

use adrianschubek\Structures\Linear\DynamicList;

$list = new DynamicList([
    "Berlin", "Munich", "Cologne"
]);

$list2 = new DynamicList([
    "Munich", "Cologne"
]);

$diff = $list->diff($list2); 
// ==> ["Berlin"]

use adrianschubek\Structures\Linear\Deque;

$deque = new Deque([
    "Berlin",
    "Munich",
    "Cologne"
]);

$deque->pop();

$ele = $deque->last();
// ==> "Munich"

use adrianschubek\Structures\Tree\BinaryTree;

$tree = new BinaryTree("Berlin");
$tree->setLeftTree(new BinaryTree("Hamburg"));
$tree->setRightTree(new BinaryTree("Munich"));

$ele = $tree->getLeftTree()->getContent();
// ==> "Hamburg"

use adrianschubek\Structures\Tree\BinarySearchTree;
use adrianschubek\Structures\Wrapper\StringWrapper;

$tree = new BinarySearchTree("Berlin");
$tree->insert(new StringWrapper("Hamburg"));
$tree->insert(new StringWrapper("Munich"));
$tree->insert(new StringWrapper("Frankfurt"));
// OR
$tree = BinarySearchTree::fromArray(["Berlin", "Hamburg", "Munich", "Frankfurt"]);
// OR
$tree = BinarySearchTree::fromString("Berlin,Munich,Frankfurt,Hamburg");

$tree->search(new StringWrapper("Frankfurt"));
// ==> "Frankfurt"

$tree->search(new StringWrapper("Mainz"));
// ==> null