php
class Node {
public $data;
public $next;
public function __construct($data) {
$this->data = $data;
$this->next = null;
}
}
class SinglyLinkedList {
private $head;
public function __construct() {
$this->head = null;
}
public function search($key) {
$current = $this->head;
while ($current != null && $current->data != $key) {
$current = $current->next;
}
if ($current == null) {
return false;
} else {
return true;
}
}
}
顶一下
(0)
0%
踩一下
(0)
0%
- 相关评论
- 我要评论
-