Last active
January 30, 2016 05:10
-
-
Save kurozumi/b774ebc550cb40dbb948 to your computer and use it in GitHub Desktop.
【PHP】シンプルな連結リストを実装
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Acme; | |
class LinkedList implements Iterator, Countable | |
{ | |
private $list; | |
public function add($value) | |
{ | |
$this->list[] = $value; | |
} | |
public function count() | |
{ | |
return count($this->list); | |
} | |
public function current() | |
{ | |
return current($this->list); | |
} | |
public function key() | |
{ | |
return key($this->list); | |
} | |
public function next() | |
{ | |
return next($this->list); | |
} | |
public function rewind() | |
{ | |
return reset($this->list); | |
} | |
public function valid() | |
{ | |
return key($this->list) !== null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment