Skip to content

Commit e5b65d7

Browse files
authored
Merge pull request #578 from remlostime/Shunting-swift
[Swift 4] Update Shunting Yard
2 parents e1bb8af + 691b556 commit e5b65d7

File tree

2 files changed

+34
-31
lines changed

2 files changed

+34
-31
lines changed

Shunting Yard/ShuntingYard.playground/Contents.swift

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
//: Playground - noun: a place where people can play
22

3+
// last checked with Xcode 9.0b4
4+
#if swift(>=4.0)
5+
print("Hello, Swift 4!")
6+
#endif
7+
38
internal enum OperatorAssociativity {
49
case leftAssociative
510
case rightAssociative
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,36 @@
11
import Foundation
22

33
public struct Stack<T> {
4-
fileprivate var array = [T]()
5-
6-
public init() {
7-
8-
}
9-
10-
public var isEmpty: Bool {
11-
return array.isEmpty
12-
}
13-
14-
public var count: Int {
15-
return array.count
16-
}
17-
18-
public mutating func push(_ element: T) {
19-
array.append(element)
20-
}
21-
22-
public mutating func pop() -> T? {
23-
return array.popLast()
24-
}
25-
26-
public var top: T? {
27-
return array.last
28-
}
4+
fileprivate var array = [T]()
5+
6+
public init() {
7+
8+
}
9+
10+
public var isEmpty: Bool {
11+
return array.isEmpty
12+
}
13+
14+
public var count: Int {
15+
return array.count
16+
}
17+
18+
public mutating func push(_ element: T) {
19+
array.append(element)
20+
}
21+
22+
public mutating func pop() -> T? {
23+
return array.popLast()
24+
}
25+
26+
public var top: T? {
27+
return array.last
28+
}
2929
}
3030

3131
extension Stack: Sequence {
32-
public func makeIterator() -> AnyIterator<T> {
33-
var curr = self
34-
return AnyIterator { _ -> T? in
35-
return curr.pop()
36-
}
37-
}
32+
public func makeIterator() -> AnyIterator<T> {
33+
var curr = self
34+
return AnyIterator { curr.pop() }
35+
}
3836
}

0 commit comments

Comments
 (0)