zoukankan      html  css  js  c++  java
  • PHP-SplDoublyLinkedList

    <?php                                                                                                                                                                                                        
    /**
     * @package a doubly linked list test
     * @author  zhaoyingnan<zhaoyn@bbtree.com>
     * @copyright
     * @version
     * @since
     **/
    
    /* SplDoublyLinkedList
     * 方法
     SplDoublyLinkedList implements Iterator , ArrayAccess , Countable
     {
         public __construct ( void )
             public void add ( mixed $index , mixed $newval ) 在指定的索引位置插入值
             public mixed bottom ( void ) 查看开始位置的节点
             public mixed top ( void ) 查看结束位置的节点
             public int count ( void ) 返回所有的元素的数量
             public void rewind ( void ) 倒回迭代器的开始
             public mixed current ( void ) 返回当前节点的信息
             public mixed key ( void ) 返回当前节点的索引
             public void setIteratorMode ( int $mode ) 设置迭代的模式
             public int getIteratorMode ( void ) 返回迭代的模式
             public bool isEmpty ( void ) 检查该双向列表是否是空的
             public void next ( void ) 移动到下一个节点
             public void prev ( void ) 移动到上一个节点
             public bool offsetExists ( mixed $index )
             public mixed offsetGet ( mixed $index )
             public void offsetSet ( mixed $index , mixed $newval )
             public void offsetUnset ( mixed $index )
             public mixed pop ( void ) 从双向列表的末尾弹出一个节点
             public void push ( mixed $value ) 向双向列表的末尾推入一个元素
             public mixed shift ( void ) 从双向列表的头部弹出一个节点
             public void unshift ( mixed $value ) 向双向列表的头部插入一个元素
             public string serialize ( void )
             public void unserialize ( string $serialized )
             public bool valid ( void ) 检查双向列表是否有更多的节点
    }
     */
    $SplDoublyLinkedList = new SplDoublyLinkedList();
    $mysqli = new mysqli('114.55.104.117', 'db_writer', 'ka_32^%*ko', 'db_community');
    if($mysqli->connect_errno)
        exit('Mysql connect error ' . $mysqli->connect_error);
    $query  = "show tables like '%zhs_user_timeline_%'";
    $result = $mysqli->query($query);
    if(!$result)
        exit('error ' . $mysqli->error);
    while($row = $result->fetch_row())
    {
        //list($arData[]) = array_values($row);
        $SplDoublyLinkedList->push($row[0]);    
    }
    $result->close();
    $mysqli->close();
    
    echo count($SplDoublyLinkedList), PHP_EOL;
    $SplDoublyLinkedList->rewind();
    while($SplDoublyLinkedList->valid())
    {
        var_export($SplDoublyLinkedList->shift());
        echo PHP_EOL;
        echo count($SplDoublyLinkedList), PHP_EOL;
        $SplDoublyLinkedList->next();
    }
    echo count($SplDoublyLinkedList);
    ?>
  • 相关阅读:
    LeetCode 382. Linked List Random Node
    LeetCode 398. Random Pick Index
    LeetCode 1002. Find Common Characters
    LeetCode 498. Diagonal Traverse
    LeetCode 825. Friends Of Appropriate Ages
    LeetCode 824. Goat Latin
    LeetCode 896. Monotonic Array
    LeetCode 987. Vertical Order Traversal of a Binary Tree
    LeetCode 689. Maximum Sum of 3 Non-Overlapping Subarrays
    LeetCode 636. Exclusive Time of Functions
  • 原文地址:https://www.cnblogs.com/yingnan/p/5659966.html
Copyright © 2011-2022 走看看