Skip to content

Commit e5dfe66

Browse files
committed
Added isEmpty, first, last
1 parent 0879118 commit e5dfe66

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

Rootish Array Stack/RootishArrayStack.swift

+16
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,22 @@ public struct RootishArrayStack<T> {
2727
return blocks.count * (blocks.count + 1) / 2
2828
}
2929

30+
var isEmpty: Bool {
31+
return blocks.count == 0
32+
}
33+
34+
var first: T? {
35+
guard capacity > 0 else { return nil }
36+
return blocks[0][0]
37+
}
38+
39+
var last: T? {
40+
guard capacity > 0 else { return nil }
41+
let block = self.block(fromIndex: count - 1)
42+
let innerBlockIndex = self.innerBlockIndex(fromIndex: count - 1, fromBlock: block)
43+
return blocks[block][innerBlockIndex]
44+
}
45+
3046
// MARK: - Equations
3147

3248
fileprivate func block(fromIndex index: Int) -> Int {

swift-algorithm-club.xcworkspace/contents.xcworkspacedata

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)