You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
hello-algo/codes/swift/chapter_stack_and_queue/stack.swift

40 lines
958 B

/**
* File: stack.swift
* Created Time: 2023-01-09
* Author: nuomi1 (nuomi1@qq.com)
*/
@main
enum Stack {
/* Driver Code */
static func main() {
/* */
// Swift Array 使
var stack: [Int] = []
/* */
stack.append(1)
stack.append(3)
stack.append(2)
stack.append(5)
stack.append(4)
print("栈 stack = \(stack)")
/* 访 */
let peek = stack.last!
print("栈顶元素 peek = \(peek)")
/* */
let pop = stack.removeLast()
print("出栈元素 pop = \(pop),出栈后 stack = \(stack)")
/* */
let size = stack.count
print("栈的长度 size = \(size)")
/* */
let isEmpty = stack.isEmpty
print("栈是否为空 = \(isEmpty)")
}
}