tipo de cubo de golang

 Mire el código de clasificación de cubos de golang, es muy simple. Realizado por tabla hash, primero almacene el valor en la tabla hash, recorra el subíndice de la tabla hash y ordene por tabla hash

package main
 
import (
	"fmt"
	"container/list"
)
 
func bucketSort(theArray []int,num int){
	var theSort [99]int
	for i:=0;i< len(theArray);i++{
		if theSort[theArray[i]] !=0{
			theSort[theArray[i]] = theSort[theArray[i]]+1
		}else{
			theSort[theArray[i]] = 1
		}
	}
	l:=list.New()
	for j:=0;j<len(theSort);j++{
		if theSort[j]==0{
			//panic("error test.....")
		}else{
			for k:=0;k<theSort[j];k++{
				l.PushBack(j)
			}
		}
	}
	for e := l.Front(); e != nil; e = e.Next() {
		fmt.Print(e.Value, " ")
	}
 
}
 
func main() {
	var theArray = []int{10, 1, 18, 30, 23, 12, 7, 5, 18, 17}
	fmt.Print("排序前")
	fmt.Println(theArray)
	fmt.Print("排序后")
	bucketSort(theArray,11)
}

 

Dirección de código: https://blog.csdn.net/stronglyh/article/details/82319329

Supongo que te gusta

Origin blog.csdn.net/ma2595162349/article/details/109397970
Recomendado
Clasificación