mirror of
https://github.com/Ed94/Odin.git
synced 2026-07-29 02:40:05 +00:00
Add sort.binary_search (uses interpolation sort for ordered numeric types)
This commit is contained in:
+14
-1
@@ -7,6 +7,7 @@ import "core:thread"
|
||||
import "core:time"
|
||||
import "core:reflect"
|
||||
import "core:runtime"
|
||||
import "core:sort"
|
||||
import "intrinsics"
|
||||
|
||||
|
||||
@@ -1978,7 +1979,19 @@ pure_procedures :: proc() {
|
||||
}
|
||||
|
||||
main :: proc() {
|
||||
when true {
|
||||
x := [?]f32{1, 1, 5, 6, 7, 8, 9, 10, 15, 15};
|
||||
i, ok := sort.binary_search(x[:], 7);
|
||||
fmt.println(x);
|
||||
fmt.println(i, ok);
|
||||
|
||||
y := [?]string{"apple", "hello", "goodbye", "what?"};
|
||||
sort.quick_sort(y[:]);
|
||||
j, y_ok := sort.binary_search(y[:], "goodbye");
|
||||
fmt.println(y);
|
||||
fmt.println(j, y_ok);
|
||||
|
||||
|
||||
when false {
|
||||
the_basics();
|
||||
control_flow();
|
||||
named_proc_return_parameters();
|
||||
|
||||
Reference in New Issue
Block a user