Read a long time data structure but not how to use, on the Internet to see the data on the structure of PHP, learn a bit, and share with you. Last time I shared a list, this time to add a two-way list. Short without cutting copy code no= $no; $this->name= $name; The static public function Addhero ($head, $hero) {$cur = $head; $isExist =false;//Determine if the current list is an empty if ($cur->next==null) {$CU R->next= $hero; $hero->pre= $cur; else {//If not an empty node, schedule name to add//find added location while ($cur->next!=null) {if ($cur->next->no > $hero->no) {break;} El Se if ($cur->next->no = = $hero->no) {$isExist =true; echo "
Cannot add the same number "; } $cur = $cur->next; } if (! $isExist) {if ($cur->next!=null) {$hero->next= $cur->next;} $hero->pre= $cur; if ($cur->next!=null {$hero->next->pre= $hero;} $cur->next= $hero; }}///traverse static public function Showhero ($head) {$cur = $head; while ($cur->next!=null) {echo
Number: ". $cur->next->no." Name: ". $cur->next->name; $cur = $cur->next; The static public function Delhero ($head, $herono) {$cur = $head; $isFind =false while ($cur!=null) {if ($cur->no== $heron O) {$isFind =true; break;}//Continue to find $cur = $cur->next; } if ($isFind) {if ($cur->next!=null) {$cur->next_pre= $cur->pre;} $cur->pre->next= $cur->next;} else {echo "
No target found "; }} $head = new Hero (); $hero 1 = new Hero (1, ' 1111 '); $hero 3 = new Hero (3, ' 3333 '); $hero 2 = new Hero (2, ' 2222 '); Hero::addhero ($head, $hero 1); Hero::addhero ($head, $hero 3); Hero::addhero ($head, $hero 2); Hero::showhero ($head); Hero::d Elhero ($head, 2); Hero::showhero ($head);?>