BinarySearchTree::createNode()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 5
1
<?php
2
/**
3
 * DataStructures for PHP
4
 *
5
 * @link      https://github.com/SiroDiaz/DataStructures
6
 * @copyright Copyright (c) 2017 Siro Díaz Palazón
7
 * @license   https://github.com/SiroDiaz/DataStructures/blob/master/README.md (MIT License)
8
 */
9
namespace DataStructures\Trees;
10
11
use DataStructures\Trees\Nodes\BSTNode;
12
use DataStructures\Trees\BinaryTreeAbstract;
13
14
/**
15
 * BinarySearchTree
16
 * 
17
 * Represents a BST actions that can be realized. All the implementation
18
 * is in BinaryTreeAbstract class.
19
 * At the beginning root is null and it can grow up to a O(n) in search,
20
 * delete and insert (in worst case). In best cases it will be O(log n).
21
 *
22
 * @author Siro Diaz Palazon <[email protected]>
23
 */
24 View Code Duplication
class BinarySearchTree extends BinaryTreeAbstract {
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
25
26
    public function __construct() {
27
        $this->root = null;
28
        $this->size = 0;
29
    }
30
31
    /**
32
     * Creates a BSTNode.
33
     *
34
     * @param int|string $key the key used to store.
35
     * @param mixed $data the data.
36
     * @param DataStructures\Trees\Nodes\BSTNode|null $parent the parent node.
37
     * @param DataStructures\Trees\Nodes\BSTNode|null $left the left child node.
38
     * @param DataStructures\Trees\Nodes\BSTNode|null $right the right child node.
39
     *
40
     * @return DataStructures\Trees\Nodes\BSTNode the new node created.
41
     */
42
    public function createNode($key, $data, $parent = null, $left = null, $right = null) {
43
        return new BSTNode($key, $data, $parent, $left, $right);
44
    }
45
}