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


PHP SplDoublyLinkedList::add方法代码示例

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


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

示例1: addChild

 /**
  * Add a child node
  *
  * If position if set on the node, add the child at that position.  This
  * will bump any node at that current position and all subsequent nodes
  * down in the list.
  *
  * This method also gives the user the ability to override the current
  * position set on the node.
  *
  * @param Node $node
  * @param int|null $position
  */
 public function addChild(Node $node, $position = null)
 {
     // if position was passed in, override current position
     if (null !== $position) {
         $node->setPosition($position);
     }
     // if the node doesn't have a position, just add it to the end
     $nodePosition = $node->getPosition();
     if (null === $nodePosition) {
         $this->children->push($node);
         return;
     }
     $this->children->add($nodePosition, $node);
 }
开发者ID:tebru,项目名称:tree,代码行数:27,代码来源:Node.php

示例2:

// offsetExists($index)
// 判断参索引是否存在,返回bool
$list->offsetExists(2);
// offsetGet($index)
// 返回参数索引的节点值
$list->offsetGet(2);
// offsetSet($index, $newValue)
// 设置参数索引的节点值, $index必须在链表的键范围中。
// 当一个节点用offsetUnset删掉时时,并不能用offsetSet重新给已删掉的节点设置值,只能对当前可见的节点的值进行修改
$list->offsetSet(3, 'value6');
// offsetUnset($index)
// 删除参数索引的节点
$list->offsetUnset(3);
// add($index, $value);
// 对指定的索引新增一个新值。 当一个节点用offsetUnset时,并没有直接删除,该节点还仍然会保存在内存中。用add可以重新给该节点设置值
$list->add(3, 'first');
// unshift($value)
// 在链表的开始节点插入value作为新的开始节点
$list->unshift('second');
// shift()
// 将链表的第一个移除
$list->shift();
// setIteratorMode(int $mode)
// 设置链表的模式。等价于下面的情况:
// IT_MODE_LIFO: 栈模式,先进后出;IT_MODE_FIFO:队列模式,先进先出
// IT_MODE_DELETE; IT_MODE_KEEP
$list->setIteratorMode(SplDoublyLinkedList::IT_MODE_FIFO);
// getIteratorMode()
// 获得链表的模式
$list->getIteratorMode();
echo "example: \n";
开发者ID:ray0916,项目名称:learn,代码行数:31,代码来源:splDoublyLinkedList.php

示例3: add

 /**
  * @param int $index
  * @param BufferInterface $value
  */
 public function add($index, $value)
 {
     $this->typeCheck($value);
     if (getenv('HHVM_VERSION') || version_compare(phpversion(), '5.5.0', 'lt')) {
         if ($index == $this->count()) {
             $this->push($value);
         } else {
             $size = count($this);
             $temp = [];
             for ($i = $size; $i > $index; $i--) {
                 array_unshift($temp, $this->pop());
             }
             $this->push($value);
             foreach ($temp as $value) {
                 $this->push($value);
             }
         }
     } else {
         parent::add($index, $value);
     }
 }
开发者ID:nmarley,项目名称:bitcoin-php,代码行数:25,代码来源:Stack.php

示例4: SplDoublyLinkedList

<?php

try {
    $dll = new SplDoublyLinkedList();
    var_dump($dll->add(12, 'Offset 12 should not exist'));
} catch (OutOfRangeException $e) {
    echo "Exception: " . $e->getMessage() . "\n";
}
开发者ID:badlamer,项目名称:hhvm,代码行数:8,代码来源:SplDoublyLinkedList_add_invalid_offset.php

示例5: SplDoublyLinkedList

<?php

try {
    $dll = new SplDoublyLinkedList();
    var_dump($dll->add(NULL, 2));
} catch (OutOfRangeException $e) {
    echo "Exception: " . $e->getMessage() . "\n";
}
开发者ID:badlamer,项目名称:hhvm,代码行数:8,代码来源:SplDoublyLinkedList_add_null_offset.php

示例6: insertToPosition

<?php

$array1 = array(1, 2, 3, 4, 5, 6, 8, 9, 10);
function insertToPosition($position, $array, $insert)
{
    $arrayTemp = array_splice($array, $position, count($array), $insert);
    return array_merge($array, $arrayTemp);
}
print_r(insertToPosition(15, $array1, 1000));
echo "<hr />" . "<br />" . "Php functions using SplDoublyLinkedList";
$list = new SplDoublyLinkedList();
for ($i = 0; $i < 10; $i++) {
    $list->push($i);
}
$list->add(5, 55);
print_r($list);
开发者ID:AlanBallesteros,项目名称:EjerciciosDiarios,代码行数:16,代码来源:php2.php

示例7: SplDoublyLinkedList

<?php

$list = new SplDoublyLinkedList();
$list->push('a');
$list->add(1, 'e');
$list->push('b');
$list->push('c');
$list->push('d');
$list->setIteratorMode(SplDoublyLinkedList::IT_MODE_FIFO);
$list->rewind();
while ($list->valid()) {
    echo $list->current(), "\n";
    $list->next();
}
开发者ID:shambhukumar,项目名称:code,代码行数:14,代码来源:SplDoublyLinkedList.php

示例8: SplDoublyLinkedList

<?php

$dll = new SplDoublyLinkedList();
var_dump($dll->add());
开发者ID:badlamer,项目名称:hhvm,代码行数:4,代码来源:SplDoublyLinkedList_add_missing_parameter1.php

示例9: count

<?php

$dll = new SplDoublyLinkedList();
// errors
try {
    $dll->add(2, 5);
} catch (OutOfRangeException $e) {
    echo "Exception: " . $e->getMessage() . "\n";
}
$dll->add(0, 6);
//	6
$dll->add(0, 3);
//	3 6
// Insert in the middle of the DLL
$dll->add(1, 4);
//	3 4 6
$dll->add(2, 5);
//	3 4 5 6
$dll->unshift(2);
//	2 3 5 4 6
// Insert at the beginning and end of the DLL
$dll->add(0, 1);
//	1 2 3 4 5 6
$dll->add(6, 7);
//	1 2 3 4 5 6 7
echo count($dll) . "\n";
echo $dll->pop() . "\n";
echo $dll->pop() . "\n";
echo $dll->pop() . "\n";
echo $dll->pop() . "\n";
echo $dll->pop() . "\n";
开发者ID:gleamingthecube,项目名称:php,代码行数:31,代码来源:ext_spl_tests_dllist_013.php

示例10: SplDoublyLinkedList

<?php

$dll = new SplDoublyLinkedList();
$dll->push('Never');
$dll->push('gonna');
$dll->push('give');
// at pos 0, shift everything up
$dll->add(0, 'you');
// Should be the end
$dll->add(4, 'up');
// Somewhere in the middle
$dll->add(2, 'let');
try {
    // Key 12 is unaccessible
    $dll->add(12, 'down');
} catch (OutOfRangeException $e) {
    echo $e->getMessage(), PHP_EOL;
}
foreach ($dll as $key => $val) {
    echo $key . '=>' . $val, PHP_EOL;
}
echo "count(): " . $dll->count(), PHP_EOL;
echo "top(): " . $dll->top(), PHP_EOL;
echo "bottom(): " . $dll->bottom(), PHP_EOL;
开发者ID:badlamer,项目名称:hhvm,代码行数:24,代码来源:SplDoublyLinkedList_add.php

示例11: SplDoublyLinkedList

<?php

$dll = new SplDoublyLinkedList();
var_dump($dll->add(2));
开发者ID:badlamer,项目名称:hhvm,代码行数:4,代码来源:SplDoublyLinkedList_add_missing_parameter2.php


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