Меню

Заказать звонок

Будни, с 9:00 до 18:00

Заказать звонок

Войти

Личный кабинет

0

echo array_pop($stack); // cherry echo array_pop($stack); // banana A queue is a First-In-First-Out (FIFO) data structure that allows elements to be added and removed. In PHP 7, queues can be implemented using arrays.

echo print_r(bfs($graph, 'A')); // Array ( [0] => A [1] => B [2] => C [3] => D [4] => E [5] => F )

echo $list->offsetGet(0); // apple echo $list->offsetGet(1); // banana A tree is a data structure composed of nodes, where each node has a value and zero or more child nodes. PHP 7 provides a SplTree class that can be used to implement trees.

function bfs($graph, $start) { $visited = array(); $queue = array($start); while (!empty($queue)) { $node = array_shift($queue); if (!in_array($node, $visited)) { $visited[] = $node; foreach ($graph[$node] as $neighbor) { if (!in_array($neighbor, $visited)) { $queue[] = $neighbor; } } } } return $visited; }

$fruits = array('apple', 'banana', 'cherry'); $fruits = ['apple', 'banana', 'cherry']; A stack is a Last-In-First-Out (LIFO) data structure that allows elements to be pushed and popped. In PHP 7, stacks can be implemented using arrays.

$stack = array(); array_push($stack, 'apple'); array_push($stack, 'banana'); array_push($stack, 'cherry');