mirror of
https://port.numenaute.org/aleajactaest/khanat-opennel-code.git
synced 2024-11-27 09:36:15 +00:00
c888a5249e
--HG-- branch : gsoc2012-achievements
33 lines
No EOL
598 B
PHP
33 lines
No EOL
598 B
PHP
<?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;
|
|
}
|
|
}
|
|
?>
|