Skip to content
Snippets Groups Projects
Commit 3a1535ed authored by FOURNEL Alexandre's avatar FOURNEL Alexandre
Browse files

question 2

parent 7e58a2d5
Branches
No related tags found
No related merge requests found
Checking pipeline status
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));
}
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment