mirror of https://github.com/01-edu/public.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
miguel
9d80904eed
|
1 year ago | |
---|---|---|
.. | ||
README.md | 1 year ago | |
main.go | 1 year ago |
README.md
issorted
Instructions
Write a function IsSorted()
that returns true
, if the slice of int
is sorted, otherwise returns false
.
-
The function passed as an argument
func(a, b int)
returns a positiveint
if the first argument is greater than the second argument, it returns0
if they are equal and it returns a negativeint
otherwise. -
To do your testing you have to write your own
f
function.
Expected function
func IsSorted(f func(a, b int) int, a []int) bool {
}
Usage
Here is a possible program to test your function (without f
):
package main
import (
"fmt"
)
func main() {
a1 := []int{0, 1, 2, 3, 4, 5}
a2 := []int{0, 2, 1, 3}
result1 := IsSorted(f, a1)
result2 := IsSorted(f, a2)
fmt.Println(result1)
fmt.Println(result2)
}
And its output:
$ go run .
true
false
$