class node{
public $value;
public $next;
function node($value){
$this->value=$value;
$this->next=null;
}
}
class Link{
public $root;
function Link($value=null){
$this->root=new node($value);
}
function getRoot(){
return $this->root;
}
function insert($value){
$p=$this->root;
while($p->next!=null){
$p=$p->next;
}
$p->next=new node($value);
}
function getlength(){
$p=$this->root;
if($p==null) return 0;
$len=0;
while($p!=null){
$len++;
}
return $len+1;
}
function deletenode($value){
$p=$this->root;
if($p==null||$p->next==null) return false;
while($p->next!=null&&$p->next->value!=$value){
$p=$p->next;
}
$p->next=$p->next->next;
return true;
}
function showLink(){
$p=$this->root;//可以是带头结点的也可以不是
while($p!=null){
echo $p->value;
$p=$p->next;
}
public $value;
public $next;
function node($value){
$this->value=$value;
$this->next=null;
}
}
class Link{
public $root;
function Link($value=null){
$this->root=new node($value);
}
function getRoot(){
return $this->root;
}
function insert($value){
$p=$this->root;
while($p->next!=null){
$p=$p->next;
}
$p->next=new node($value);
}
function getlength(){
$p=$this->root;
if($p==null) return 0;
$len=0;
while($p!=null){
$len++;
}
return $len+1;
}
function deletenode($value){
$p=$this->root;
if($p==null||$p->next==null) return false;
while($p->next!=null&&$p->next->value!=$value){
$p=$p->next;
}
$p->next=$p->next->next;
return true;
}
function showLink(){
$p=$this->root;//可以是带头结点的也可以不是
while($p!=null){
echo $p->value;
$p=$p->next;
}
}
}