File tree 2 files changed +18
-3
lines changed
main/java/com/thealgorithms/sorts
test/java/com/thealgorithms/sorts 2 files changed +18
-3
lines changed Original file line number Diff line number Diff line change 1
1
package com .thealgorithms .sorts ;
2
2
3
+ /**
4
+ * BinaryInsertionSort class implements the SortAlgorithm interface using the binary insertion sort technique.
5
+ * Binary Insertion Sort improves upon the simple insertion sort by using binary search to find the appropriate
6
+ * location to insert the new element, reducing the number of comparisons in the insertion step.
7
+ */
3
8
public class BinaryInsertionSort implements SortAlgorithm {
4
9
5
- // Binary Insertion Sort method
10
+ /**
11
+ * Sorts the given array using the Binary Insertion Sort algorithm.
12
+ *
13
+ * @param <T> the type of elements in the array, which must implement the Comparable interface
14
+ * @param array the array to be sorted
15
+ * @return the sorted array
16
+ */
6
17
public <T extends Comparable <T >> T [] sort (T [] array ) {
7
18
for (int i = 1 ; i < array .length ; i ++) {
8
19
T temp = array [i ];
Original file line number Diff line number Diff line change 4
4
5
5
import org .junit .jupiter .api .Test ;
6
6
7
- class BinaryInsertionSortTest {
7
+ class BinaryInsertionSortTest extends SortingAlgorithmTest {
8
+ private final BinaryInsertionSort binaryInsertionSort = new BinaryInsertionSort ();
8
9
9
- BinaryInsertionSort binaryInsertionSort = new BinaryInsertionSort ();
10
+ @ Override
11
+ SortAlgorithm getSortAlgorithm () {
12
+ return binaryInsertionSort ;
13
+ }
10
14
11
15
@ Test
12
16
// valid test case
You can’t perform that action at this time.
0 commit comments