Skip to content

Instantly share code, notes, and snippets.

@kurozumi
Last active January 30, 2016 05:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kurozumi/b774ebc550cb40dbb948 to your computer and use it in GitHub Desktop.
Save kurozumi/b774ebc550cb40dbb948 to your computer and use it in GitHub Desktop.
【PHP】シンプルな連結リストを実装
<?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