-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathQueue.ps1
More file actions
43 lines (32 loc) · 778 Bytes
/
Queue.ps1
File metadata and controls
43 lines (32 loc) · 778 Bytes
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
. $PSScriptRoot\..\linked-list\LinkedList.ps1
class Queue {
$linkedList
Queue() {
$this.linkedList = New-Object LinkedList
}
[bool] isEmpty() {
return !$this.linkedList.tail
}
[object] peek() {
if (!$this.linkedList.head) {
return $null
}
return $this.linkedList.head.value
}
enqueue($value) {
$this.linkedList.append($value)
}
[object] dequeue() {
$removedHead = $this.linkedList.deleteHead()
if($removedHead) {
return $removedHead.value
}
return $null
}
[string] toString() {
return $this.toString($null)
}
[string] toString($callback) {
return $this.linkedList.toString($callback)
}
}