PHP List Usage Example analysis, PHP usage example Analysis _php tutorial

Source: Internet
Author: User

PHP List Usage Example analysis, PHP usage Example analysis


This example describes the use of the PHP list. Share to everyone for your reference. Specific as follows:

This article briefly introduces the basic usage of the list of PHP, including the creation, traversal, updating and other operations of the linked list nodes.

<?php/** * @author mzxy * @copyright * @param PHP List *//**** node class */class node{private $Data;//node data private $Next;  /Next node Public function SetData ($value) {$this->data= $value;  The Public Function Setnext ($value) {$this->next= $value;  } public Function GetData () {return $this->data;  } public Function GetNext () {return $this->next;    The Public function __construct ($data, $next) {$this->setdata ($data);  $this->setnext ($next);    }}//function class linklist{private $header;//head node private $size;//Length Public Function GetSize () {$i = 0;    $node = $this->header;      while ($node->getnext ()!=null) {$i + +;    $node = $node->getnext ();  } return $i;  The Public Function SetHeader ($value) {$this->header= $value;  } public Function GetHeader () {return $this->header; } public Function __construct () {header ("content-type:text/html;    Charset=utf-8 ");  $this->setheader (New Node (Null,null)); }/** * @author mzxy * @param $data--Data to be added to the node * */Public Function Add ($data) {$node = $this->header;    while ($node->getnext ()!=null) {$node = $node->getnext ();  } $node->setnext (new node ($data, null));    }/** * @author mzxy * @param $data-Data to remove the node * */Public Function removeAt ($data) {$node = $this->header;    while ($node->getdata ()! = $data) {$node = $node->getnext ();    } $node->setnext ($node->getnext ());  $node->setdata ($node->getnext ()->getdata ());    }/** * @author mzxy * @param traversal * * */Public function get () {$node = $this->header;      if ($node->getnext () ==null) {print ("The DataSet is empty!");    Return      } while ($node->getnext ()!=null) {print ($node->getnext ()->getdata ());      if ($node->getnext ()->getnext () ==null) {break;}    $node = $node->getnext (); }}/** * @author mzxy * @param $data-The data of the node to be accessed * @param This method only demonstrates no practical meaning * */Public Function getAt ($data) {$ Node= $this-&GT;HEADER-&GT;GETNExt ();      if ($node->getnext () ==null) {print ("The DataSet is empty!");    Return      } while ($node->getdata ()! = $data) {if ($node->getnext () ==null) {break;}    $node = $node->getnext ();      } return $node->getdata ();  }/** * @author mzxy * @param $value--The original data of the node that needs to be updated--$initial---updated data * */Public Function update ($initial, $value)     {$node = $this->header->getnext ();      if ($node->getnext () ==null) {print ("The DataSet is empty!");    Return      } while ($node->getdata ()! = $data) {if ($node->getnext () ==null) {break;}    $node = $node->getnext ();     } $node->setdata ($initial); }}?>

I hope this article is helpful to everyone's PHP programming.

http://www.bkjia.com/PHPjc/1029598.html www.bkjia.com true http://www.bkjia.com/PHPjc/1029598.html techarticle PHP List Usage example analysis, PHP Usage Example Analysis of this article describes the PHP list usage. Share to everyone for your reference. As follows: Here is a brief introduction to the basic use of the list of PHP ...

  • 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.