khanat-code-old/code/web/app/app_achievements/class/NodeIterator_class.php

33 lines
598 B
PHP
Raw Normal View History

2014-02-21 19:39:24 +00:00
<?php
class NodeIterator {
/*---------------------------
The NodeIterator can be used to iterate linked lists.
Sample:
$iter = new NodeIterator(array());
while($iter->hasNext()) {
$curr = $iter->getNext();
// ...
}
---------------------------*/
private $node;
function NodeIterator($node) {
$this->node = $node;
}
function hasNext() {
if($this->node == null) {
return false;
}
return true;
}
function getNext() {
$n = $this->node;
$this->node = $this->node->getChild();
return $n->data;
}
}
?>