链表定义
来源:互联网 发布:minecraftpe凡家物语js 编辑:程序博客网 时间:2024/06/07 08:18
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;
}
}
}
0 0
- 链表的定义
- 链表的定义
- 链表的定义
- C++链表定义
- 链表定义
- typedef 定义链表 出错
- 链表模板类的定义
- C++链表结构定义的理解
- (一)链表函数定义文件
- 链表的定义与简单操作
- 二级链表的定义和用法
- 链表的定义及其基本运算
- Java 链表的定义与使用
- python的链表定义以及实现
- 链表的定义与操作
- 链表的定义以及实现
- 定义对象模型(定义表)
- 供应链管理 定义
- java之旅之JDBC
- innodb/myisam区别
- Java集合类的使用
- PAT 乙级 锤子剪刀布 (20)
- Goal Modeling:KAOS
- 链表定义
- linux下输出文件夹下所有文件夹名称并重定向
- 用自己写的接口文档生成工具生成入参出参文档
- Git常用命令总结
- android开发技巧收集
- python学习之(7)正则表达式篇
- 关于linux下安装eclipse后可能出现空格键变短的情况
- 深度学习资料
- iOS绘图_Quartz 2D基础