Skip to content

Instantly share code, notes, and snippets.

@tchrist
Created October 31, 2011 21:10
Show Gist options
  • Save tchrist/1328966 to your computer and use it in GitHub Desktop.
Save tchrist/1328966 to your computer and use it in GitHub Desktop.
LL - iterator
Implement a linked list and supporting classes:
LinkedList implementing the Iterator interface: http://php.net/manual/en/class.iterator.php
class LinkedList
Node $root;
//additionally, implement the functions below:
GetElements(); //returns an array of all elements in the linked list
insert($val); //insert a value at the current position in the linked list
delete(); //delete the current value in the linked list
Node
Node $next, $prev;
$val;
next(); //returns the next node in the list
prev(); //returns the previous value in the list
All functions should be unit tested using PHPUnit and the code should be provided with a suite of executable tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment