Created
August 21, 2014 00:01
-
-
Save dannolan/91bc74ed42939214d499 to your computer and use it in GitHub Desktop.
2darray
This file contains hidden or 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
class Array2D<T> { | |
let columns: Int | |
let rows: Int | |
var array: Array<T?> // private | |
init(columns: Int, rows: Int) { | |
self.columns = columns | |
self.rows = rows | |
array = Array<T?>(count: rows*columns, repeatedValue: nil) | |
} | |
subscript(column: Int, row: Int) -> T? { | |
get { | |
return array[row*columns + column] | |
} | |
set { | |
array[row*columns + column] = newValue | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment