Examples of php linked list usage and php usage. Php linked list usage example analysis, php Usage example analysis this article describes the php linked list usage. Share it with you for your reference. Details: This section briefly introduces the use of php linked list usage instance analysis, and php Usage instance analysis.
This example describes the usage of the php linked list. Share it with you for your reference. The details are as follows:
This section briefly introduces the basic usage of php linked list, including creating, traversing, and updating linked list nodes.
<? Php/*** @ author MzXy * @ copyright 2011 * @ param PHP linked list * // ***** Node class */class Node {private $ Data; // node Data private $ Next; // the Next node public function setData ($ value) {$ this-> Data = $ value;} public function setNext ($ value) {$ this-> Next = $ value;} public function getData () {return $ this-> Data;} public function getNext () {return $ this-> Next ;} public function _ construct ($ data, $ next) {$ this-> setData ($ data); $ this-> SetNext ($ next) ;}/// function class LinkList {private $ header; // header node private $ size; // length public function getSize () {$ I = 0; $ node = $ this-> header; while ($ node-> getNext ()! = Null) {$ I ++; $ node = $ node-> getNext () ;}return $ I;} 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 of the node to be added **/public function add ($ data) {$ node = $ this-> header; while ($ node-> getN Ext ()! = Null) {$ node = $ node-> getNext () ;}$ node-> setNext (new Node ($ data, null ));} /*** @ author MzXy * @ param $ data -- data of the node to be removed **/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 () = null) {break;} $ node = $ node-> getNext ();}} /*** @ author MzXy * @ param $ data -- data of the node to be accessed * @ param this method only demonstrates non-practical significance **/public function getAt ($ data) {$ 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 ();} return $ node-> getData ();} /*** @ author MzXy * @ param $ value -- original data of the node 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 will help you with php programming.
Examples in this article describes the usage of the php linked list. Share it with you for your reference. Details: This section briefly introduces the basic use of php linked list...