Before the blog Park search found no PHP implementation of the list, in Baidu also almost no! So put the code on it!
I think there are some flaws in this code, what is it? is the type of constraint is not strict enough! PHP itself is a weak type of language!
So in this piece is a bit confused! Forget the pointers! I am a novice!
Here is the code
Node class
Class node{ private $Data; node Data private $Next; next node public function SetData ($value) {$ This , Data = $value;} Public function Setnext ($value) {$ This and Next = $value;} Public function GetData () { return $ This, Data;} Public function GetNext () { return $ this and Next;} Public function __construct ($data, $next) {$ setData ($data); Setnext ($next);} }
Function class
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 add node * */Public Function Add ($data) {$node = $ the 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, set Next ($node-GetNext ()); GetData (SetData, $node, GetNext, $node); }/* * * @author MZXY * @param traversal * */Public function get () {$node = $ this-& Gt 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-& Gt GetNext (); }}//* * @author Mzxy * @param $data-The data of the node to be accessed * @paRam This method simply demonstrates no actual meaning * */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--The original data of the node that needs to be updated--$initial---updated data * */Public Function update ($ Initial, $value) {$node = $ this, header, and 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); } }