Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created November 22, 2022 21:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/7ee868701f6b2f521358c717ad6c4b9a to your computer and use it in GitHub Desktop.
Save parzibyte/7ee868701f6b2f521358c717ad6c4b9a to your computer and use it in GitHub Desktop.
func particion(arreglo *[]ProductoVendidoParaGrafica, izquierda, derecha int64) int64 {
var pivote = (*arreglo)[izquierda]
for {
for (*arreglo)[izquierda].VecesVendido > pivote.VecesVendido {
izquierda++
}
for (*arreglo)[derecha].VecesVendido < pivote.VecesVendido {
derecha--
}
if izquierda >= derecha {
return derecha
} else {
(*arreglo)[izquierda], (*arreglo)[derecha] = (*arreglo)[derecha], (*arreglo)[izquierda]
izquierda++
derecha--
}
}
}
func quicksort(arreglo *[]ProductoVendidoParaGrafica, izquierda, derecha int64) {
if izquierda < derecha {
indiceParticion := particion(arreglo, izquierda, derecha)
quicksort(arreglo, izquierda, indiceParticion)
quicksort(arreglo, indiceParticion+1, derecha)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment