March 2019
Intermediate to advanced
336 pages
9h 9m
English
A zig-zag matrix is a square arrangement of n x n integers. The integers are arranged on anti-diagonals in sequentially increasing order. The following code explains how to create a zig-zag matrix and also how to traverse it. The PrintZigZag method creates the matrix in a zig-zag fashion with the elements in a sequentially increasing order. The method takes the integer n as a parameter and returns the integer array, which is the zig-zag matrix:
///main package has examples shown// in Go Data Structures and algorithms bookpackage main// importing fmt packageimport ( "fmt")//prints the matrix in zig-zag fashionfunc PrintZigZag(n int) []int { var zigzag []int zigzag = make([]int, n*n) var i int i = 0 var m int m = n * 2 ...
Read now
Unlock full access