Just learning PHP, the master can give a use of PHP to implement the linked list and two-tree code
Ask the master to give a list and two tree related executable code
Data structure of the linked list:
Class Lnode
{
Private $data;
Private $next;
}
Binary Tree data structure:
Class Tnode
{
Private $data;
Private $lchild;
Private $rchild;
}
Thank you!
------Solution--------------------
PHP array can simulate many kinds of structures.
------Solution--------------------
PHP code
!--? phpclass lnode{public $data; Public $next; }class Lists {private $root; function Lists () {$this--->root = new Lnode; } function Append ($v) {$sp =& $this->root; while (! empty ($SP)) $sp =& $sp->next; $SP = new Lnode; $sp->data = $v; } function Delete ($v) {$sp =& $this->root; while (! empty ($SP) && $sp->next->data! = $v) $sp =& $sp->next; if ($sp) $sp->next = $sp->next->next; }} $p = new Lists; $p->append (' A '); $p->append (' B '); $p->append (' C ');p rint_r ($p); $p->delete (' B ');p Rint_r ( $p);