PHP standard Library (SPL)-Data structure (i)-spldoublylinkedlist detailed ___ data structure

Source: Internet
Author: User
Tags spl prev rewind


SPL is a collection of interfaces and classes that are used to troubleshoot a typical problem (standard problems).

1. Spldoublylinkedlist
prototype:


SplDoublyLinkedList Implements iterator, arrayaccess, countable {/* Method/Public __construct (void) public void Add (mixed $index, mix Ed $newval) public mixed Bottom (void) public int count (void) public mixed current (void) public int Getiteratormo De (void) public bool IsEmpty (void) public mixed key (void) public void next (void) public bool Offsetexists (MI Xed $index) public mixed offsetget (mixed $index) public void Offsetset (mixed $index, mixed $newval) Fsetunset (mixed $index) public mixed pops (void) public void prev (void) public void push (mixed $value) public Vo
ID 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)} 

Example:


 Constructs a new doubly linked list $list = new Spldoublylinkedlist ();
    Pushes an element in 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 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 (); }




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.