博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
php单链表实现
阅读量:4597 次
发布时间:2019-06-09

本文共 1650 字,大约阅读时间需要 5 分钟。

php单链表实现

no=$no;$this->name=$name; }}function addHero($head,$Hero){ $cur=$head; $flag=true; while ($cur->next!=null) { if($cur->next->no>$Hero->no){ $tmp=$cur->next; $cur->next=$Hero; $Hero->next=$tmp; $flag=false;break; }else if($cur->next->no==$Hero->no){
echo "该位置已有人,不允许占位";$flag=false;break;} else{ $cur=$cur->next;} } if($flag){
$cur->next=$Hero;}}//增加function showHero($head){ $cur=$head; while($cur->next!=null){ echo $cur->next->no.":".$cur->next->name."
"; $cur=$cur->next; } }//删除特定编号的 function delHero($head,$no){ $cur=$head; while($cur->next!=null){ if($cur->next->no==$no) {
if($cur->next->next)$cur->next=$cur->next->next; else $cur->next=null; break; } $cur=$cur->next; } } //查找特定编号的信息 function findHero($head,$no){ $cur=$head; while($cur->next!=null){ if($cur->next->no==$no){
break;} $cur=$cur->next; } echo$cur->next->name; } //改特定编号的信息 function updateHero($head,$no,$name){ $cur=$head; while($cur->next!=null){ if($cur->next->no==$no){
break;} $cur=$cur->next; }$cur->next->name=$name; }$head=new Hero();$Hero=new Hero(1,"宋江");addHero($head,$Hero);$Hero=new Hero(6,"林冲");addHero($head,$Hero);$Hero=new Hero(2,"吴用");addHero($head,$Hero);$Hero=new Hero(4,"李逵");addHero($head,$Hero);showHero($head);//删除4号delHero($Hero,4);//查找6号findHero($head,6);// 修改6号updateHero($Hero,6,"林哥哥");showHero($head);?>

 

转载于:https://www.cnblogs.com/HKUI/p/3278423.html

你可能感兴趣的文章
(文件过多时)删除目录下全部文件
查看>>
T-SQL函数总结
查看>>
python 序列:列表
查看>>
web移动端
查看>>
pythonchallenge闯关 第13题
查看>>
linux上很方便的上传下载文件工具rz和sz使用介绍
查看>>
React之特点及常见用法
查看>>
【WEB前端经验之谈】时间一年半,或沉淀、或从零开始。
查看>>
优云软件助阵GOPS·2017全球运维大会北京站
查看>>
linux 装mysql的方法和步骤
查看>>
poj3667(线段树区间合并&区间查询)
查看>>
51nod1241(连续上升子序列)
查看>>
SqlSerch 查找不到数据
查看>>
集合相关概念
查看>>
Memcache 统计分析!
查看>>
(Python第四天)字符串
查看>>
个人介绍
查看>>
使用python动态特性时,让pycharm自动补全
查看>>
关于R软件的安装
查看>>
MySQL数据库免安装版配置
查看>>