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.
20 lines
384 B
20 lines
384 B
package solutions |
|
|
|
func IsSorted(f func(int, int) int, arr []int) bool { |
|
ascendingOrdered := true |
|
descendingOrdered := true |
|
|
|
for i := 1; i < len(arr); i++ { |
|
if !(f(arr[i-1], arr[i]) >= 0) { |
|
ascendingOrdered = false |
|
} |
|
} |
|
|
|
for i := 1; i < len(arr); i++ { |
|
if !(f(arr[i-1], arr[i]) <= 0) { |
|
descendingOrdered = false |
|
} |
|
} |
|
|
|
return ascendingOrdered || descendingOrdered |
|
}
|
|
|