March 2019
Intermediate to advanced
336 pages
9h 9m
English
The merge sort algorithm is a comparison-based method that was invented by John Von Neumann. Each element in the adjacent list is compared for sorting. The performance of the algorithm is in the order of O(n log n). This algorithm is the best algorithm for sorting a linked list.
The following code snippet demonstrates the merge sort algorithm. The createArray function takes num int as a parameter and returns an integer, array, that consists of randomized elements:
//main package has examples shown// in Go Data Structures and algorithms bookpackage main// importing fmt and bytes packageimport ( "fmt" "math/rand" "time")// create arrayfunc createArray(num int) []int { var array []int array = make([]int, num, num) rand.Seed(time.Now().UnixNano()) ...Read now
Unlock full access