refactor: use internal method and remove toArray() method

This commit is contained in:
nuomi1
2023-01-11 23:54:04 +08:00
parent 99f1494939
commit ac7d26c131
3 changed files with 12 additions and 24 deletions

View File

@ -29,8 +29,9 @@ class ArrayStack {
}
/* */
@discardableResult
func pop() -> Int {
if stack.isEmpty {
if isEmpty() {
fatalError("栈为空")
}
return stack.removeLast()
@ -38,7 +39,7 @@ class ArrayStack {
/* 访 */
func peek() -> Int {
if stack.isEmpty {
if isEmpty() {
fatalError("栈为空")
}
return stack.last!

View File

@ -20,7 +20,7 @@ class LinkedListStack {
/* */
func isEmpty() -> Bool {
_size == 0
size() == 0
}
/* */
@ -32,6 +32,7 @@ class LinkedListStack {
}
/* */
@discardableResult
func pop() -> Int {
let num = peek()
_peek = _peek?.next
@ -41,7 +42,7 @@ class LinkedListStack {
/* 访 */
func peek() -> Int {
if _size == 0 {
if isEmpty() {
fatalError("栈为空")
}
return _peek!.val