Skip to content
oldlinux edited this page Aug 3, 2014 · 1 revision

Quick Sort


Usage

use intArray or strArray to define []int or []string.

You can use them simply like this:

x := intArray {1,2,3,1}
QuickSort(x, 0, x.Len()-1)

y := strArray {'hello', 'go', 'algorithms'}
QuickSort(y, 0, y.Len()-1)

Both intArray and strArray implements interface Ord

type Ord interface {
	Swap(i, j int)  
	Less(i,j int) bool 
	Len() int
}

You can implements Ord interface to make your own type sortable.

Benchmark

About 700ms for sort 1,000,000 random number

Reference

[quick sort wiki]

Clone this wiki locally