March 2019
Intermediate to advanced
336 pages
9h 9m
English
A struct type (class) can be sorted using different sets of multiple fields. In the sort_multi_keys.go code, we show how to sort struct types. A class called Commit consists of the username, lang, and numlines properties. username is a string, lang is a string, and numlines is an integer. In the following code, the Commit class is sorted by commits and lines:
///main package has examples shown// in Go Data Structures and algorithms bookpackage main// importing fmt and sort packageimport ( "fmt" "sort")// A Commit is a record of code checkingtype Commit struct { username string lang string numlines int}
In the next section, the implementation of the multiSorter class is discussed.
Read now
Unlock full access