国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 天峻县| 桦南县| 济南市| 林口县| 清流县| 岑巩县| 营山县| 吉首市| 阳东县| 汶川县| 义马市| 合水县| 遂昌县| 齐齐哈尔市| 闻喜县| 启东市| 周口市| 渝北区| 天峻县| 邵东县| 滦南县| 海淀区| 大渡口区| 长葛市| 玉屏| 张家界市| 岚皋县| 吴堡县| 甘泉县| 云林县| 南昌县| 衡山县| 邳州市| 措美县| 平泉县| 东安县| 广东省| 忻城县| 瓮安县| 新邵县| 东兰县|