diff --git a/src/main/java/fr/univamu/sorting/SortableIntList.java b/src/main/java/fr/univamu/sorting/SortableIntList.java new file mode 100644 index 0000000000000000000000000000000000000000..c709b4aa8c732acd7c5f5a8dd60ca3e6d95bc9cd --- /dev/null +++ b/src/main/java/fr/univamu/sorting/SortableIntList.java @@ -0,0 +1,44 @@ +package fr.univamu.sorting; +import java.util.*; + +public class SortableIntList { + public ArrayList<Integer> IntList; + + public void swap(int index1, int index2){ + int value1 = IntList.get(index1); + int value2 = IntList.get(index2); + IntList.set(index1, value1); + IntList.set(index2, value2); + } + + public int compare(int index1, int index2){ + if (IntList.get(index1) > IntList.get(index2)){ + return 1; + } + else if (IntList.get(index1) < IntList.get(index2)) { + return -1; + } + else { + return 0; + } + + } + + public int size(){ + return IntList.size(); + } + + public int get(int index){ + return IntList.get(index); + } + public void sort(){ + for (int i = 0; i < IntList.size() - 1; i++) + { + for (int j = i + 1; j < IntList.size(); j++) { + if (compare(IntList.get(j),IntList.get(i)) < 0){ + swap(IntList.get(i),IntList.get(j)); + } + + } + } +}