Example #1
0
 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'");
     }
 }
Example #2
0
 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);
     }
 }
Example #3
0
 /**
  * @param ListNode $node
  * @return bool
  */
 public final function contains(ListNode $node)
 {
     return array_key_exists($node->getId(), $this->nodes);
 }
Example #4
0
File: Path.php Project: tvswe/astar
 /**
  * @param ListNode $node
  * @return Node
  */
 public function convertNode(ListNode $node)
 {
     return new Node($node->getId(), $node->getX(), $node->getY());
 }