php標準庫(SPL)-資料結構(一)-SplDoublyLinkedList詳解____資料結構

來源:互聯網
上載者:User


SPL是用於解決典型問題(standard problems)的一組介面與類的集合。

1. SplDoublyLinkedList     
原型:


SplDoublyLinkedList implements Iterator , ArrayAccess , Countable {/* 方法 */public __construct ( void )public void add ( mixed $index , mixed $newval )public mixed bottom ( void )public int count ( void )public mixed current ( void )public int getIteratorMode ( void )public bool isEmpty ( void )public mixed key ( void )public void next ( 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 prev ( void )public void push ( mixed $value )public void rewind ( void )public string serialize ( void )public void setIteratorMode ( int $mode )public mixed shift ( void )public mixed top ( void )public void unserialize ( string $serialized )public void unshift ( mixed $value )public bool valid ( void )}

樣本:


 //Constructs a new doubly linked list    $list = new SplDoublyLinkedList();    //Pushes an element at the end of the doubly linked list    $list -> push('a');    $list -> push('b');    $list -> push('c');    $list -> push('d');    $list -> push('e');    $list -> push('f');    // Counts the number of elements in the doubly linked list.    $list -> count();    // Sets the mode of iteration    $list -> setIteratorMode(SplDoublyLinkedList::IT_MODE_LIFO);    // Returns the mode of iteration    $model = $list -> getIteratorMode();    /*  IT_MODE_LIFO => int(2)     *  IT_MODE_FIFO => int(0)     *  IT_MODE_DELETE => int(1)     *  IT_MODE_KEEP => int(0)      */    // Checks whether the doubly linked list is empty.    $list -> isEmpty();    // Return current node index    $list->key();    // Move to next entry    $list -> next();    // Returns whether the requested $index exists    $list -> offsetExists(3);      // Returns the value at the specified $index    $list -> offsetGet(3);    // Sets the value at the specified $index to $newval    $list -> offsetSet(3,'s');    // Unsets the value at the specified $index    $list -> offsetUnset(3);    // Pops a node from the end of the doubly linked list    $list -> pop();    // Peeks at the node from the end of the doubly linked list    $list -> top();    // Move to previous entry    $list -> prev();    // Rewind iterator back to the start    $list -> rewind();    // Serializes the storage    // $list -> serialize();    // Shifts a node from the beginning of the doubly linked list    $list -> shift();    // Prepends the doubly linked list with an element    $list -> unshift('s');    // Check whether the doubly linked list contains more nodes    $list -> valid();    for($list -> rewind();$list -> valid();$list -> next()){        //Return current array entry        echo $list -> current();    }




相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.