PHP implementation single-linked list (static linked list)
data = $data; $next && $this->next = $next; } public Function GetData () {return $this->data; The Public Function SetData ($data) {$this->data = $data; } public Function GetNext () {return $this->next; The Public Function Setnext ($next) {$this->next = $next; }}//single-linked list class linklist{private $data _list = NULL;//Node Set Public function linklist ($dat A = False) {$this->data_list = array (); $title = new Node (NULL); $this->data_list[] = $title; if ($data) {if (Is_array ($data)) {$this->addmoredata ($data); }else{$this->adddata ($data); }}}//Returns the value of the nth node public function Getnodebynumber () {return $this->da ta_list[$this->findkeybynumbER ()]->getdata (); }//Add a set of node public function Addmoredata ($datas) {foreach ($datas as $value) {$this-& Gt;adddata ($value); }}//Add node Unity entry for Outer call//added at the end of the first node public function AddData ($data, = False) { $node = new node ($data); if (= = = FALSE | | = = COUNT ($this->data_list)) {$this->insertlastnode ($node); }elseif (> count ($this->data_list)) {return false; }else{$this->insertnode ($node,); }}//Insert a node to the last Private function Insertlastnode ($node) {$node->setnext (NULL); $lastKey = $this->findlastnode (); $insert _key = $this->insertnodeintoarray ($node); $this->data_list[$lastKey]->setnext ($insert _key); }//Insert a node PrivaTe function Insertnode ($node,) {$insert _number = $this->findkeybynumber (); $node->setnext ($this->data_list[$insert _number]->getnext ()); $insert _key = $this->insertnodeintoarray ($node); $this->data_list[$insert _number]->setnext ($insert _key); }//find the corresponding array of nth nodes key Private function Findkeybynumber () {$i = $key = 0; while ($i <) {$key = $this->data_list[$key]->getnext (); $i + +; } return $key; }//Add nodes to the array private function Insertnodeintoarray ($node) {$this->data_list[] = $node; return $this->getlastkey (); }//Delete node public function Deletenode () {if (= = 0 | | > COUNT ($this->dat A_list)) {return false; } $pre _key = $this->findkeybynumber ($nuMBER-1); $key = $this->data_list[$pre _key]->getnext (); $this->data_list[$pre _key]->setnext ($this->data_list[$key]->getnext ()); unset ($this->data_list[$key]); }//Find the previous node of a node private function Getprenodekey ($key) {foreach ($this->data_list as $k = + $v) { if ($v->getnext () = = $key) {return $k; }} return false; }//Print List public function getdata_list () {return $this->data_list; }//Returns the last key of the array private function Getlastkey () {End ($this->data_list); Return key ($this->data_list); }//Determine if a key value exists Private function Ifexistkey ($key) {if (Array_key_exists ($key, $this->data_list)) {return true; } return false; }//Find tail node Public function Findlastnode () { foreach ($this->data_list as $key = + $value) {if ($value->getnext () = = = NULL) {R Eturn $key; }}}}?>