新聞中心
這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
php遍歷樹(shù)的常用方法有哪些-創(chuàng)新互聯(lián)
這篇文章主要介紹php遍歷樹(shù)的常用方法有哪些,文中介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們一定要看完!
具體如下:
一、遞歸的深度優(yōu)先的算法:
----------------------- Test run for '.$func.'() '; flush(); $time_start = microtime(true); $list = $func($trydir); //print_r($list); $time = microtime(true) - $time_start; echo 'Finished : '.count($list).' files'; $mem2 = memory_get_peak_usage(); printf('
Max memory for '.$func.'() : %0.2f kbytes Running time for '.$func.'() : %0.f s', ($mem2-$mem1)/1024.0, $time); return $list; } profile('rec_list_files', "D:\www\server"); ?>
二、遞歸的深度優(yōu)先的算法(用了一個(gè)棧來(lái)實(shí)現(xiàn))
----------------------- Test run for '.$func.'() '; flush(); $time_start = microtime(true); $list = $func($trydir); //print_r($list); $time = microtime(true) - $time_start; echo 'Finished : '.count($list).' files'; $mem2 = memory_get_peak_usage(); printf('
Max memory for '.$func.'() : %0.2f kbytes Running time for '.$func.'() : %0.f s', ($mem2-$mem1)/1024.0, $time); return $list; } profile('deep_first_list_files', "D:\www\server"); ?>
三、非遞歸的廣度優(yōu)先算法(用了一個(gè)隊(duì)列來(lái)實(shí)現(xiàn))
NEXT CHILD } return $files; // end of tree, file not found } function profile($func, $trydir) { $mem1 = memory_get_usage(); echo '----------------------- Test run for '.$func.'() '; flush(); $time_start = microtime(true); $list = $func($trydir); //print_r($list); $time = microtime(true) - $time_start; echo 'Finished : '.count($list).' files'; $mem2 = memory_get_peak_usage(); printf('Max memory for '.$func.'() : %0.2f kbytes Running time for '.$func.'() : %0.f s', ($mem2-$mem1)/1024.0, $time); return $list; } profile('breadth_first_files', "D:\www\server"); ?>
以上是“php遍歷樹(shù)的常用方法有哪些”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對(duì)大家有幫助,更多相關(guān)知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!
新聞標(biāo)題:php遍歷樹(shù)的常用方法有哪些-創(chuàng)新互聯(lián)
文章位置:http://www.ef60e0e.cn/article/dshdeo.html