真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

利用PHP怎么實(shí)現(xiàn)一個(gè)雙向鏈表功能-創(chuàng)新互聯(lián)

利用PHP怎么實(shí)現(xiàn)一個(gè)雙向鏈表功能?很多新手對(duì)此不是很清楚,為了幫助大家解決這個(gè)難題,下面小編將為大家詳細(xì)講解,有這方面需求的人可以來(lái)學(xué)習(xí)下,希望你能有所收獲。

創(chuàng)新互聯(lián)公司始終堅(jiān)持【策劃先行,效果至上】的經(jīng)營(yíng)理念,通過(guò)多達(dá)10年累計(jì)超上千家客戶(hù)的網(wǎng)站建設(shè)總結(jié)了一套系統(tǒng)有效的全網(wǎng)推廣解決方案,現(xiàn)已廣泛運(yùn)用于各行各業(yè)的客戶(hù),其中包括:成都衛(wèi)生間隔斷等企業(yè),備受客戶(hù)夸獎(jiǎng)。

代碼如下:



        class Hero
        {
            public $pre=null;
            public $no;
            public $name;
            public $next=null;
            public function __construct($no='',$name='')
            {
                $this->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 "
沒(méi)有找到目標(biāo)";
                }               
            }
        }
        $head = new Hero();
        $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);
?>


看完上述內(nèi)容是否對(duì)您有幫助呢?如果還想對(duì)相關(guān)知識(shí)有進(jìn)一步的了解或閱讀更多相關(guān)文章,請(qǐng)關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝您對(duì)創(chuàng)新互聯(lián)網(wǎng)站建設(shè)公司,的支持。


文章標(biāo)題:利用PHP怎么實(shí)現(xiàn)一個(gè)雙向鏈表功能-創(chuàng)新互聯(lián)
文章網(wǎng)址:http://weahome.cn/article/eegio.html

其他資訊

在線(xiàn)咨詢(xún)

微信咨詢(xún)

電話(huà)咨詢(xún)

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部