Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Vector2D {
- var x : Int
- var y : Int
- let map : [[Int]]
- init(_ v: [[Int]]) {
- map = v
- x = 0
- y = 0
- }
- func next() -> Int {
- hasNext()
- let n = map[x][y]
- y += 1
- return n
- }
- func hasNext() -> Bool {
- if map.count == 0 {return false}
- if y >= map[x].count{
- x += 1
- //find next available row
- while x < map.count && map[x].count == 0 {
- x += 1
- }
- if x >= map.count {return false}
- y = 0
- }
- return true
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement