File tree Expand file tree Collapse file tree
Shunting Yard/ShuntingYard.playground Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+
38internal enum OperatorAssociativity {
49 case leftAssociative
510 case rightAssociative
Original file line number Diff line number Diff line change 11import Foundation
22
33public 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
3131extension 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}
You can’t perform that action at this time.
0 commit comments