Написать (на любом языке функцию), которая обращает список.
NB: Решения через array_reverse
, array_map
и прочие array_штуковины
не принимаются.
Пример на php:
<?php
final class ListElement {
private $id;
private $next;
public function __construct($id) {
$this->id = $id;
}
public function getId() {
return $this->id;
}
public function getNext() {
return $this->next;
}
public function setNext(ListElement $next) {
$this->next = $next;
return $this->next;
}
}
$list = new ListElement(1);
$last = $list
->setNext(new ListElement(2))
->setNext(new ListElement(4))
->setNext(new ListElement(7)); // 8, 9 ... 9001 и т.д.
// $last->setNext($list); // так тоже бывает
function f($list) {
// Тут решение
}
$reverse = f($list);
print_r($reverse);
var_dump(spl_object_hash($reverse) == spl_object_hash(f(f($reverse)))); // true