php實現簡單的單鏈表

2022-02-15 15:27:51 字數 907 閱讀 8379

<?php

/** * 建立乙個鍊錶,節點的data為陣列,記錄乙個id,完成鍊錶所以操作

*///結點,結點資料data定義為乙個陣列,id和value

class node

}class linklist

//向尾部新增結點

public function add(node $node)

$current->next = $node; }

//遍歷列表,列印結點

public function show() }

//獲取鍊錶長度,不含頭結點(空)

public function getlength()

return $len; }

//查詢value是否在list中,存在返回id,否則false

public function find($value)

$current = $current->next;

} if($flag == 0)else }

//插入乙個結點,在id之前

public function insert(node $node,$id)

$current = $current->next;

} }//刪除乙個結點(第乙個出現的)

public function del($id)

$current = $current->next;

} }//更新結點value

public function update($id,$value)

$current = $current->next;

} }}class client

}client::main();

?>

增加結點、刪除結點、查詢結點、修改結點、獲取長度,遍歷均實現。

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 ...

單鏈表簡單實現

單鏈表的形式 頭部有個head節點每個節點都向後關聯乙個節點 下面是我的單鏈表的插刪改查和反轉的操作 include include include typedef struct node list define node size sizeof struct node typedef struct...

單鏈表的簡單實現

include include include define max list length 20 define expand list length 5 using namespace std include include typedef struct node node,list 初始化乙個l...