国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 網(wǎng)站 > 建站經(jīng)驗(yàn) > 正文

PHP、實(shí)現(xiàn)雙向鏈表

2019-11-02 15:19:30
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

   看了很久數(shù)據(jù)結(jié)構(gòu)但是沒有怎么用過(guò),在網(wǎng)上看到了關(guān)于PHP的數(shù)據(jù)結(jié)構(gòu),學(xué)習(xí)了一下,與大家一起分享一下。上一次分享了鏈表,這次來(lái)補(bǔ)充說(shuō)一下雙向鏈表。 簡(jiǎn)短不割 復(fù)制代碼 no=$no; $this->name=$name; } static public function addHero($head,$hero) { $cur = $head; $isExist=false; //判斷目前這個(gè)鏈表是否為空 if($cur->next==null) { $cur->next=$hero; $hero->pre=$cur; } else { //如果不是空節(jié)點(diǎn),則安排名來(lái)添加 //找到添加的位置 while($cur->next!=null) { if($cur->next->no > $hero->no) { break; } else if($cur->next->no == $hero->no) { $isExist=true; echo "

  不能添加相同的編號(hào)"; } $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; } } } //遍歷 static public function showHero($head) { $cur=$head; while($cur->next!=null) { echo "

  編號(hào):".$cur->next->no."名字:".$cur->next->name; $cur=$cur->next; } } static public function delHero($head,$herono) { $cur=$head; $isFind=false; while($cur!=null) { if($cur->no==$herono) { $isFind=true; break; } //繼續(xù)找 $cur=$cur->next; } if($isFind) { if($cur->next!=null) { $cur->next_pre=$cur->pre; } $cur->pre->next=$cur->next; } else { echo "

  沒有找到目標(biāo)"; } } } $head = new H

順口溜[www.62-6.com/1/marenbaodian/]
ero(); $hero1 = new Hero(1,'1111'); $hero3 = new Hero(3,'3333'); $hero2 = new Hero(2,'2222'); Hero::addHero($head,$hero1); Hero::addHero($head,$hero3); Hero::addHero($head,$hero2); Hero::showHero($head); Hero::delHero($head,2); Hero::showHero($head); ?>

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 泗洪县| 广饶县| 南宁市| 通化县| 岗巴县| 青田县| 镇坪县| 盖州市| 抚州市| 永靖县| 西宁市| 文昌市| 文昌市| 上虞市| 芦溪县| 金坛市| 乡宁县| 吉木乃县| 怀仁县| 洪江市| 四子王旗| 黄龙县| 颍上县| 青川县| 黎川县| 县级市| 安吉县| 津市市| 阿克苏市| 巴林左旗| 古蔺县| 县级市| 图木舒克市| 佛坪县| 蒲城县| 土默特左旗| 碌曲县| 漠河县| 华蓥市| 文化| 龙海市|