Last active
April 8, 2019 01:57
-
-
Save anettodev/a25067b61641779cb85df5169daea8fc 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
// Orders Protocol | |
protocol Orders { | |
associatedtype Item | |
func enqueue(item:Item) | |
func dequeue() -> Item? | |
func showCurrentQueue() -> [Item] | |
} | |
// RestaurantOrders class | |
class RestaurantOrders<Item>: Orders { | |
var items : [Item] = [Item]() | |
func enqueue(item: Item){ | |
items.append(item) | |
} | |
func dequeue() -> Item? { | |
if !items.isEmpty { | |
return items.removeFirst() | |
} | |
else { | |
return nil | |
} | |
} | |
func showCurrentQueue() -> [Item] { | |
return items | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment