Created
April 30, 2020 18:34
-
-
Save stoiandan/1c68197e564c01932496155c7962c0f3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
class Rod { | |
fileprivate var stack = [Int]() | |
public func stackOnTop(diskSize newDiskSize: Int) throws { | |
if let topDiskSize = stack.popLast() { | |
guard topDiskSize > newDiskSize else { | |
throw RodSizeError.RodSizeIsTooHigh(topDiskSize: topDiskSize, diskToBeInsertedSize: newDiskSize) | |
} | |
} | |
stack.append(newDiskSize) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment