<?php //instantiate the list $ll = new JDoublyLinkedList(); //First node goes after the head. $firstNode = $ll->createNode('First Node'); $ll->addFirst($firstNode); //10 more nodes for ($i = 0; $i < 5; $i++) { $node = $ll->createNode('Node-' . $i); $ll->addNext($firstNode, $node); $firstNode = $node; } //and this is how we iterate...iterate $it = new JLinkedListIterator($ll); foreach ($it as $k => $v) { echo '<pre>', $k, ': ', print_r($v, true), '</pre>'; } unset($ll, $it); echo 'Peak: ' . number_format(memory_get_peak_usage(), 0, '.', ',') . " bytes<br>"; echo 'End: ' . number_format(memory_get_usage(), 0, '.', ',') . " bytes<br>"; /* The output would be something like this: [sourcecode language="HTML"] Initial: 126,360 bytes 4d7f677322b38: JNode Object ( [_value:private] => First Node [_previous:private] => 4d7f677322b06
/** * JLinkedListIterator::__construct() * * @param mixed $ll * @return */ public function __construct(JDoublyLinkedList $ll) { $this->_list = $ll->getList(); $this->_ll = $ll; $this->rewind(); }