-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLinkedList.php
More file actions
81 lines (62 loc) · 1.55 KB
/
LinkedList.php
File metadata and controls
81 lines (62 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
class LinkedList
{
private $first_node = null;
private $last_node = null;
// Accept a constructor argument later
public function __construct()
{
}
// Adds to the beginning of the list
public function unshift($var)
{
$node = new Node($var);
if ($this->first_node !== null) {
$node->setNext($this->first_node);
$this->first_node->setPrev($node);
}
$node->first_node = $node;
}
// Returns the first item and shortens the list by 1
public function shift()
{
}
// Adds to the end of the list
public function push($var)
{
$node = new Node($var);
if ($this->last_node !== null) {
$node->setPrev($this->last_node);
$this->last_node->setNext($node);
}
$this->last_node = $node;
}
// Returns the last item and shortens the list by 1
public function pop()
{
}
public function first()
{
return $this->first_node;
}
public function last()
{
return $this->last_node;
}
public function insertBefore(Node $node, $var)
{
}
public function insertAfter(Node $node, $var)
{
$new_node = new Node($var);
$new_node->setPrev($node);
$new_node->setNext($node->getNext());
$node->setNext($new_node);
}
public function removeBefore(Node $node)
{
}
public function removeAfter(Node $node)
{
}
}