Logo

Programming-Idioms

History of Idiom 17 > diff from v35 to v36

Edit summary for version 36 by ricardo_sdl:
New PHP implementation by user [ricardo_sdl]

Version 35

2018-04-03, 08:28:06

Version 36

2018-08-29, 20:41:05

Idiom #17 Create a Tree data structure

The structure must be recursive. A node may have zero or more children. A node has access to children nodes, but not to its parent.

Idiom #17 Create a Tree data structure

The structure must be recursive. A node may have zero or more children. A node has access to children nodes, but not to its parent.

Code
class Tree {
    public $children = [];
    public $data;
    
    public function __construct($data, $children) {
        $this->data = $data;
        $this->children = $children;
    }
    
}
Demo URL
https://3v4l.org/GIgDC