public static function testNode() { // test ListNode() $listNode1 = new ListNode('test'); if ($listNode1->getData() !== 'test') { self::printError("problem setting intial data"); } // $listNode2 = new ListNode('test2'); $listNode2->next =& $listNode1; if ($listNode2->next->getData() !== 'test') { self::printError("problem updating next on List Node"); } $listNode3 = new ListNode('test3', $listNode2); if ($listNode3->next->next->getData() !== 'test') { self::printError("problem constructing new node with existing link - next->next->data is not 'test'"); } }
public function insert($data) { $curr = $this->curr; if (!empty($curr)) { $prev = $curr->get_prev(); $next = $curr->get_next(); $node = new ListNode($data); $node->set_prev($curr); $node->set_next($next); $curr = $this->curr = $node; return $curr->get_key(); } else { return $this->add($data); } }
/** * @param ListNode $node * @return bool */ public final function contains(ListNode $node) { return array_key_exists($node->getId(), $this->nodes); }
/** * @param ListNode $node * @return Node */ public function convertNode(ListNode $node) { return new Node($node->getId(), $node->getX(), $node->getY()); }