-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathStack.ps1
More file actions
58 lines (46 loc) · 1.19 KB
/
Stack.ps1
File metadata and controls
58 lines (46 loc) · 1.19 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
. $PSScriptRoot\..\linked-list\LinkedList.ps1
. $PSScriptRoot\..\linked-list\LinkedListNode.ps1
class Stack {
$linkedList
Stack() {
$this.linkedList = New-Object LinkedList
}
[bool] isEmpty() {
return !$this.linkedList.tail
}
[object] peek() {
if ($this.isEmpty()) {
return $null
}
return $this.linkedList.tail.value
}
push($value) {
$this.linkedList.append($value)
}
[object] pop() {
$removedTail = $this.linkedList.deleteTail()
if ($removedTail) {
return $removedTail.value
}
else {
return $null
}
#return removedTail ? removedTail.value : null;
}
[object] toArray() {
[System.Collections.ArrayList]$a = $this.linkedList.toArray().value
$a.Reverse()
return $a
# return (3, 2, 1)
# return this.linkedList
# .toArray()
# .map(linkedListNode => linkedListNode.value)
# .reverse();
}
[object] ToString() {
return $this.linkedList.toString()
}
[object] ToString($callback) {
return $this.linkedList.toString($callback)
}
}