Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 02a91b7

Browse files
committed
Implemented Sort interface in InsertionSort and SelectionSort
1 parent be80d09 commit 02a91b7

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/main/java/br/com/zevolution/algorithms/sorting/insertionsort/InsertionSort.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package br.com.zevolution.algorithms.sorting.insertionsort;
22

33
import br.com.zevolution.algorithms.sorting.Product;
4+
import br.com.zevolution.algorithms.sorting.Sort;
45

5-
public class InsertionSort {
6+
public class InsertionSort implements Sort {
67

7-
public static Product[] sortingByCheapest(Product[] products, int length) {
8+
public Product[] sort(Product[] products, int length) {
89
Product[] array = products.clone();
910
for (int current = 1; current < length; current++) {
1011
int beingAnalyzed = current;

src/main/java/br/com/zevolution/algorithms/sorting/selectionsort/SelectionSort.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package br.com.zevolution.algorithms.sorting.selectionsort;
22

33
import br.com.zevolution.algorithms.sorting.Product;
4+
import br.com.zevolution.algorithms.sorting.Sort;
45

5-
public class SelectionSort {
6+
public class SelectionSort implements Sort {
67

7-
public static Product[] sortingByCheapest(Product[] products, int length) {
8+
public Product[] sort(Product[] products, int length) {
89
Product[] array = products.clone();
910
for (int current = 0; current < length - 1; current++) {
1011
int cheapest = getCheapest(array, current, length - 1);
@@ -18,7 +19,7 @@ public static Product[] sortingByCheapest(Product[] products, int length) {
1819
return array;
1920
}
2021

21-
private static int getCheapest(Product[] products, int beginIndex, int endIndex) {
22+
private int getCheapest(Product[] products, int beginIndex, int endIndex) {
2223
int cheapest = beginIndex;
2324
for (int current = beginIndex; current <= endIndex; current++) {
2425
if (products[current].getPrice() < products[cheapest].getPrice()) {

0 commit comments

Comments
 (0)