File tree Expand file tree Collapse file tree 2 files changed +19
-0
lines changed
classical_algorithms/dart Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Original file line number Diff line number Diff line change
1
+ int binarySearch <T extends Comparable <Object >>(List <T > sortedList, T value) {
2
+ int min = 0 ;
3
+ int max = sortedList.length;
4
+ while (min < max) {
5
+ final int mid = min + ((max - min) >> 1 );
6
+ final T element = sortedList[mid];
7
+ final int comp = element.compareTo (value);
8
+ if (comp == 0 ) {
9
+ return mid;
10
+ }
11
+ if (comp < 0 ) {
12
+ min = mid + 1 ;
13
+ } else {
14
+ max = mid;
15
+ }
16
+ }
17
+ return - 1 ;
18
+ }
Original file line number Diff line number Diff line change @@ -36,6 +36,7 @@ Code | Test
36
36
------------ | -------------
37
37
[ Bubble Sort] ( https://github.com/larissalages/code_problems/blob/master/classical_algorithms/dart/BubbleSort.dart ) | Missing tests
38
38
[ Quick Sort] ( https://github.com/larissalages/code_problems/blob/master/classical_algorithms/dart/QuickSort.dart ) | Missing tests
39
+ [ Binary Sort] ( https://github.com/larissalages/code_problems/blob/master/classical_algorithms/dart/BinarySort.dart ) | Missing tests
39
40
40
41
### C++
41
42
Code | Test
You can’t perform that action at this time.
0 commit comments