Quick Sort in Go

Read more articles on Go, Algorithms
Quick Sort in Go

Subscribe

Get updated 1 - 2 times a month when new articles are published, no spam ever.

Introduction #

In this article you are going to write the Quick Sort algorithm in Go.

Quick Sort in Go #

 
go
func quicksort(arr []int) { qsort(arr, 0, len(arr) - 1) } func qsort(arr []int, start, end int) { if end-start < 1 { return } pivot := arr[end] left := start right := end - 1 for left <= right { if arr[left] > pivot { arr[left], arr[right] = arr[right], arr[left] right-- continue } left++ } arr[end], arr[left] = arr[left], arr[end] qsort(arr, start, left-1) qsort(arr, left+1, end) }
quicksort.go

Subscribe

Get updated 1 - 2 times a month when new articles are published, no spam ever.

    TheDeveloperCafe Ā© 2022-2024