php單鏈表實現
<?php//單鏈表
class
hero
}function addhero($head,$hero
)else
if($cur->next->no==$hero->no)
else
}if($flag)}//
增加function showhero($head) }
//刪除特定編號的
function delhero($head,$no
)
$cur=$cur->next
; } }
//查詢特定編號的資訊
function findhero($head,$no
)
$cur=$cur->next
; }
echo
$cur->next->name; }
//改特定編號的資訊
function updatehero($head,$no,$name
)
$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
);?>
線性單鏈表的實現(php)
單鏈表的實現 線性表介面 inte ce llist 單鏈表資料結點類 class node class singlylinkedlist implements llist function add value else q new node value q next p next p next q...
用PHP實現的單鏈表
單鏈表顧名思義就是乙個鏈式資料結構,它有乙個表頭,並且除了最後乙個節點外,所有節點都有其後繼節點。如下圖。鍊錶節點 class node 鍊錶中還有兩個特別重要的方法,插入和刪除。插入需要找到插入的位置,把前乙個元素的next指標指向被插入的節點,並將被插入節點的next指標指向後乙個節點,如下圖左...
用PHP實現的單鏈表
單鏈表顧名思義就是乙個鏈式資料結構,它有乙個表頭,並且除了最後乙個節點外,所有節點都有其後繼節點。如下圖。首先,我們寫出鍊錶節點的類。單鏈表中的每乙個節點,都儲存其資料域和後驅指標 鍊錶節點 class node 鍊錶中還有兩個特別重要的方法,插入和刪除。插入需要找到插入的位置,把前乙個元素的nex...