hello-algo/codes/swift/chapter_stack_and_queue/stack.swift
2023-01-10 08:05:07 +08:00

39 lines
958 B
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* 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)")
}
}