Trying to get the sorting to work
Currently only gets the smallest number and prints it equal to the amount of numbers in the original array, slices are a pain to deal with
This commit is contained in:
parent
2bcbe7edc9
commit
07d8c34480
|
@ -1,3 +1,5 @@
|
||||||
module array-sorter
|
module array-sorter
|
||||||
|
|
||||||
go 1.21.6
|
go 1.21.6
|
||||||
|
|
||||||
|
require git.bulgariu.xyz/raul/min-max-array v0.0.0-20240131105739-41c2fcc5af70
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
git.bulgariu.xyz/raul/min-max-array v0.0.0-20240131105739-41c2fcc5af70 h1:q/uQwkakAZnaus16KHG6UkBFZzNaMbjY3SCZjh0Pytk=
|
||||||
|
git.bulgariu.xyz/raul/min-max-array v0.0.0-20240131105739-41c2fcc5af70/go.mod h1:PdMyknNgNZYKg03bYhSc4aaSA/P3yScGPfxC4z+ju0c=
|
|
@ -2,6 +2,7 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"git.bulgariu.xyz/raul/min-max-array"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
@ -12,7 +13,8 @@ var err error
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
if len(os.Args) < 2 {
|
if len(os.Args) < 2 {
|
||||||
fmt.Println("[-] Not enough arguments")
|
fmt.Println("Tool to automatically sort an array from the smallest number to the largest")
|
||||||
|
fmt.Println("Usage: ./array-sorter 20 5 10")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
for i := 1; i < (len(os.Args)); i++ {
|
for i := 1; i < (len(os.Args)); i++ {
|
||||||
|
@ -25,7 +27,7 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("RESULTS:")
|
fmt.Println("RESULTS:")
|
||||||
fmt.Println(numArray)
|
fmt.Printf("%v\n", numArray)
|
||||||
|
|
||||||
fmt.Printf("\nSORTED RESULTS:\n")
|
fmt.Printf("\nSORTED RESULTS:\n")
|
||||||
sortedArray := sorter(numArray)
|
sortedArray := sorter(numArray)
|
||||||
|
@ -36,10 +38,33 @@ func sorter(arr []float64) (orderedArr []float64) {
|
||||||
if len(arr) == 0 {
|
if len(arr) == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var numLocation int
|
||||||
|
var numValue float64
|
||||||
|
sliced_arr := arr
|
||||||
|
|
||||||
|
// TODO: get the actual sorting working
|
||||||
for i := 0; i < len(arr); i++ {
|
for i := 0; i < len(arr); i++ {
|
||||||
for _, v := range arr {
|
mini := minmax.Min(sliced_arr)
|
||||||
orderedArr = append(orderedArr, v)
|
orderedArr = append(orderedArr, mini)
|
||||||
|
|
||||||
|
// TESTING (DELETING) ZONE
|
||||||
|
|
||||||
|
for i, v := range sliced_arr {
|
||||||
|
if v == minmax.Min(arr) {
|
||||||
|
numLocation = i
|
||||||
|
numValue = v
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sliced_arr = append(sliced_arr[:numLocation], sliced_arr[numLocation:]...)
|
||||||
|
// TESTING ZONE
|
||||||
|
|
||||||
}
|
}
|
||||||
return
|
fmt.Printf("\nThe smallest value is %v and its position is %v\n\n", numValue, numLocation)
|
||||||
|
//fmt.Printf("AAAA: %v", numLocation)
|
||||||
|
//fmt.Printf("the identifier for the smallest number is %v", numLocation)
|
||||||
|
// Why are you like this
|
||||||
|
|
||||||
|
return orderedArr
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue