当前位置: 首页>>代码示例>>PHP>>正文


PHP Node::setNext方法代码示例

本文整理汇总了PHP中Node::setNext方法的典型用法代码示例。如果您正苦于以下问题:PHP Node::setNext方法的具体用法?PHP Node::setNext怎么用?PHP Node::setNext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Node的用法示例。


在下文中一共展示了Node::setNext方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testGetIntersectingNode

 public function testGetIntersectingNode()
 {
     $a1 = new Node("one");
     $a2 = new Node("two");
     $a3 = new Node("three");
     $a4 = new Node("four");
     $a5 = new Node("five");
     $a1->setNext($a2);
     $a2->setNext($a3);
     $a3->setNext($a4);
     $a4->setNext($a5);
     $b1 = new Node("un");
     $b2 = new Node("deux");
     $b3 = new Node("trois");
     $b1->setNext($b2);
     $b2->setNext($b3);
     $this->assertNull(LinkedListIntersectionChecker::getIntersectingNode($a1, $b1));
     $c1 = new Node("uno");
     $c2 = new Node("dos");
     $c3 = new Node("tres");
     $c1->setNext($c2);
     $c2->setNext($c3);
     $a5->setNext($c1);
     $b3->setNext($c1);
     $this->assertSame($c1, LinkedListIntersectionChecker::getIntersectingNode($a1, $b1));
 }
开发者ID:SamyGhannad,项目名称:CtCI-6th-Edition,代码行数:26,代码来源:LinkedListIntersectionCheckerTest.php

示例2: testGetIntersectingNode

 public function testGetIntersectingNode()
 {
     $a1 = new Node("one");
     $a2 = new Node("two");
     $a3 = new Node("three");
     $a4 = new Node("four");
     $a5 = new Node("five");
     $a1->setNext($a2);
     $a2->setNext($a3);
     $a3->setNext($a4);
     $a4->setNext($a5);
     $b1 = new Node("un");
     $b2 = new Node("deux");
     $b3 = new Node("trois");
     $b1->setNext($b2);
     $b2->setNext($b3);
     $this->assertNull(LinkedListIntersectionCheckerNoHashMap::getIntersectingNode($a1, $b1));
     $c1 = new Node("uno");
     $c2 = new Node("dos");
     $c3 = new Node("tres");
     $c1->setNext($c2);
     $c2->setNext($c3);
     $a5->setNext($c1);
     $b3->setNext($c1);
     $this->assertSame($c1, LinkedListIntersectionCheckerNoHashMap::getIntersectingNode($a1, $b1));
     // disconnect the first 4 nodes of the linked list.
     // now it begins @ $a5
     $a4->setNext(null);
     $this->assertSame($c1, LinkedListIntersectionCheckerNoHashMap::getIntersectingNode($a5, $b1));
 }
开发者ID:SamyGhannad,项目名称:CtCI-6th-Edition,代码行数:30,代码来源:LinkedListIntersectionCheckerNoHashMapTest.php

示例3: push

 public function push($value)
 {
     $newHead = new Node($value);
     $newHead->setNext($this->linkedList);
     $this->linkedList = $newHead;
     $this->size++;
 }
开发者ID:SamyGhannad,项目名称:CtCI-6th-Edition,代码行数:7,代码来源:SizedStack.php

示例4: __construct

 /**
  * All object initialized with NULL as its head.
  *
  * @return void
  */
 public function __construct()
 {
     // Sentinel is dummy object before head and after tail.
     $sentinel = new Node(NULL);
     $sentinel->setNext($sentinel);
     $sentinel->setPrev($sentinel);
     $this->_sentinel = $sentinel;
     $this->_head = $this->_sentinel;
 }
开发者ID:Baft,项目名称:Algorithm-and-Data-Structure-in-PHP,代码行数:14,代码来源:linked_list_using_class.php

示例5: deleteNodeFromLinkedList

 public static function deleteNodeFromLinkedList(Node $node)
 {
     if ($node === null) {
         throw new InvalidArgumentException('node is null');
     }
     $next = $node->getNext();
     if ($next === null) {
         throw new InvalidArgumentException('node is not in the middle of a linked list');
     }
     // overwrite values in the deleted node with the ones from the next node.
     $node->setData($next->getData());
     $node->setNext($next->getNext());
 }
开发者ID:SamyGhannad,项目名称:CtCI-6th-Edition,代码行数:13,代码来源:MiddleNodeDeleter.php

示例6: toLinkedListOfDigits

 public static function toLinkedListOfDigits($number)
 {
     $head = null;
     $base = 1;
     while ($number > 0) {
         $nextBase = $base * 10;
         $remainder = $number % $nextBase;
         $digit = new Node($remainder / $base);
         $digit->setNext($head);
         $head = $digit;
         $number -= $remainder;
         $base = $nextBase;
     }
     return $head;
 }
开发者ID:SamyGhannad,项目名称:CtCI-6th-Edition,代码行数:15,代码来源:SumListReversed.php

示例7: testGetIntersectingNode

 public function testGetIntersectingNode()
 {
     $n1 = new Node("one");
     $n2 = new Node("two");
     $n3 = new Node("three");
     $n4 = new Node("four");
     $n5 = new Node("five");
     $n1->setNext($n2);
     $n2->setNext($n3);
     $n3->setNext($n4);
     $n4->setNext($n5);
     $this->assertNull(LinkedListCycleDetector::getCycleNode($n1));
     // create a cycle
     $n5->setNext($n3);
     $this->assertSame($n3, LinkedListCycleDetector::getCycleNode($n1));
 }
开发者ID:rockhx1987,项目名称:CtCI-6th-Edition,代码行数:16,代码来源:LinkedListCycleDetectorTest.php

示例8: push

 public function push($value)
 {
     $newHead = new Node($value);
     if ($this->linkedList === null) {
         $this->linkedList = $newHead;
         $this->min = new Node($value);
     } else {
         $newHead->setNext($this->linkedList);
         $this->linkedList = $newHead;
         if ($value < $this->min->getData()) {
             $newMin = new Node($value);
             $newMin->setNext($this->min);
             $this->min = $newMin;
         }
     }
 }
开发者ID:SamyGhannad,项目名称:CtCI-6th-Edition,代码行数:16,代码来源:StackMin.php

示例9: partition

 public static function partition(Node $node, $x)
 {
     $head = $node;
     $previousNode = null;
     while ($node !== null) {
         if ($node->getData() < $x && $previousNode !== null) {
             // remove the node from this part of the list
             $previousNode->setNext($node->getNext());
             // put this node at the begining of the list
             $node->setNext($head);
             // reset head
             $head = $node;
             // reset node for the next iteration
             $node = $previousNode;
         } else {
             $previousNode = $node;
             $node = $node->getNext();
         }
     }
     return $head;
 }
开发者ID:SamyGhannad,项目名称:CtCI-6th-Edition,代码行数:21,代码来源:LinkedListPartitioner.php

示例10: ListInsert

 public function ListInsert($i, $data)
 {
     //后插
     $j = 1;
     //从第一个元素开始遍历
     $node = $this->_headNode;
     // 指向头结点
     while ($node && $j < $i) {
         $node = $node->getNext();
         $j++;
     }
     if (!$node || $j > $i) {
         // $i个结点不存在时
         return "err";
     }
     $newNode = new Node();
     $newNode->setData($data);
     $newNode->setNext($node->getNext());
     $node->setNext($newNode);
     return true;
 }
开发者ID:Code-Ken,项目名称:Data-Structures-And-Algorithms-With-PHP,代码行数:21,代码来源:SingleLinkedList.class.php

示例11: testSumWithMultipleCarryOperations

 public function testSumWithMultipleCarryOperations()
 {
     $a1 = new Node(1);
     $b1 = new Node(9);
     $b2 = new Node(9);
     $b3 = new Node(9);
     $b4 = new Node(9);
     $b5 = new Node(9);
     $b1->setNext($b2);
     $b2->setNext($b3);
     $b3->setNext($b4);
     $b4->setNext($b5);
     $node = SumListNoConvert::sum($a1, $b1);
     $this->assertEquals(0, $node->getData());
     $node = $node->getNext();
     $this->assertEquals(0, $node->getData());
     $node = $node->getNext();
     $this->assertEquals(0, $node->getData());
     $node = $node->getNext();
     $this->assertEquals(0, $node->getData());
     $node = $node->getNext();
     $this->assertEquals(0, $node->getData());
     $node = $node->getNext();
     $this->assertEquals(1, $node->getData());
     $node = $node->getNext();
     $this->assertNull($node);
 }
开发者ID:SamyGhannad,项目名称:CtCI-6th-Edition,代码行数:27,代码来源:SumListNoConvertTest.php

示例12: attach

 /**
  * Adds a node to the head of the list
  * @param Node $head the node object that represents the head of the list
  * @param Node $node the node to move to the head of the list
  */
 private function attach($head, $node)
 {
     $node->setPrevious($head);
     $node->setNext($head->getNext());
     $node->getNext()->setPrevious($node);
     $node->getPrevious()->setNext($node);
 }
开发者ID:jhammer,项目名称:php-lrucache,代码行数:12,代码来源:LRUCache.php

示例13: testToInteger

 public function testToInteger()
 {
     $n1 = new Node(6);
     $n2 = new Node(1);
     $n3 = new Node(7);
     $n1->setNext($n2);
     $n2->setNext($n3);
     $this->assertEquals(617, SumListReversed::toInteger($n1));
 }
开发者ID:SamyGhannad,项目名称:CtCI-6th-Edition,代码行数:9,代码来源:SumListReversedTest.php

示例14: testFindBeginningOfCycleWithCircularListOfSizeFive

 public function testFindBeginningOfCycleWithCircularListOfSizeFive()
 {
     $n1 = new Node("one");
     $n2 = new Node("two");
     $n3 = new Node("three");
     $n4 = new Node("four");
     $n5 = new Node("five");
     $n1->setNext($n2);
     $n2->setNext($n3);
     $n3->setNext($n4);
     $n4->setNext($n5);
     $n5->setNext($n1);
     $cycleNode = LinkedListCycleDetector::findBeginningOfCycle($n1);
     $this->assertSame($n1, $cycleNode, 'Expected: ' . $n1->getData() . ' Found: ' . $cycleNode->getData());
 }
开发者ID:SamyGhannad,项目名称:CtCI-6th-Edition,代码行数:15,代码来源:LinkedListCycleDetectorTest.php


注:本文中的Node::setNext方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。