March 2019
Intermediate to advanced
336 pages
9h 9m
English
Two-dimensional arrays were presented briefly in Chapter 2, Getting Started with Go for Data Structures and Algorithms. To recap, for dynamic allocation, we use slice of slices, which is a two-dimensional array. A two-dimensional array, is a list of single-dimensional arrays. Every element in a two-dimensional array arr, is identified as arr[i][j], where arr is the name of the array and i and j represent rows and columns, and their values ranging from 0 to m and 0 to n, respectively. Traversing a two-dimensional array is of O(m*n) complexity.
The following code shows how to initialize an array:
var arr = [4][5] int{ {4,5,7,8,9}, {1,2,4,5,6}, {9,10,11,12,14}, {3,5,6,8,9}}
An element in a two-dimensional array is accessed ...
Read now
Unlock full access