Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Quick sorting under goalng

Shulou Source: shulou.com Published: 2022-06-03 04:16:57 09月20日 Update

Always feel that their data structure learning is not very good, take the time to practice the basic algorithm.

Let's take a picture first and learn about the algorithm.

Cdn2.b0.upaiyun.com/2012/01/Visual-and-intuitive-feel-of-7-common-sorting-algorithms.gif ">

Here is the code implementation of golang. Welcome to beat the brick.

The algorithm is relatively simple, that is, I have been thinking about it on the node out of the stack for a long time, which is welcome.

Package main

Import (

"fmt"

)

Const (

Greaterthan = iota / / greater than

Equal / equals

Lessthan / / less

)

/ / compare

Func comparedata (D1 int, D2 int) int {

If D1 < D2 {

Return lessthan

} else if D1 = = D2 {

Return equal

} else {

Return greaterthan

}

}

/ / Exchange

Func swap (D1 * int, D2 * int) {

Var temp int

Temp = * D1

* D1 = * D2

* D2 = temp

Return

}

/ / sort

Func quicksort (datalist [] int, left int, right int) {

Var middle int

Middle = (left + right) / 2

If middle = = left {

Return

}

If middle = = right {

Return

}

Fmt.Println ("left", left, "right", right)

For I: = left; I

Tags: Algorithms data sorting code basics that is data structures nodes jackers first come learn Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn OPPO Reno Shulou Technology Shulou Information Huawei