diff --git a/array-sorter/go.mod b/array-sorter/go.mod index 3d0b255..0399acc 100644 --- a/array-sorter/go.mod +++ b/array-sorter/go.mod @@ -1,3 +1,5 @@ module array-sorter go 1.21.6 + +require git.bulgariu.xyz/raul/min-max-array v0.0.0-20240131105739-41c2fcc5af70 diff --git a/array-sorter/go.sum b/array-sorter/go.sum new file mode 100644 index 0000000..73bf989 --- /dev/null +++ b/array-sorter/go.sum @@ -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= diff --git a/array-sorter/main.go b/array-sorter/main.go index b7a88ed..7599431 100644 --- a/array-sorter/main.go +++ b/array-sorter/main.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "git.bulgariu.xyz/raul/min-max-array" "os" "strconv" ) @@ -12,7 +13,8 @@ var err error func main() { 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) } for i := 1; i < (len(os.Args)); i++ { @@ -25,7 +27,7 @@ func main() { } fmt.Println("RESULTS:") - fmt.Println(numArray) + fmt.Printf("%v\n", numArray) fmt.Printf("\nSORTED RESULTS:\n") sortedArray := sorter(numArray) @@ -36,10 +38,33 @@ func sorter(arr []float64) (orderedArr []float64) { if len(arr) == 0 { 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 _, v := range arr { - orderedArr = append(orderedArr, v) + mini := minmax.Min(sliced_arr) + 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 }