Skip to content
Snippets Groups Projects
Commit 67d1269d authored by ADAMOU Salim's avatar ADAMOU Salim
Browse files

correction de App.java et creation de SortableIntArray; de SortableIntList et debut de Sort.java.

parent 37d7a18d
Branches
No related tags found
No related merge requests found
Pipeline #24409 failed
......@@ -7,6 +7,8 @@ public class App {
public static void main(String[] args) {
List<Integer> shuffled = IntLists.shuffledRange(0,1000);
SortableIntList sortableIntList = new SortableIntList(shuffled);
sortableIntList.sort();
System.out.println(
shuffled.stream()
.map(String::valueOf)
......
package fr.univamu.sorting;
public class Sort {
public void sort(){
bubbleSort();
}
public void bubbleSort(){
for( int i=0; i< data.size()-1; i++){
for(int j=0 ; j< data.size()-1-i; j++){
if(compare(j,j+1)>0){
Swap(j,j+1);
}
}
}
}
}
package fr.univamu.sorting;
import java.util.List;
public class SortableIntArray {
private int[]data;
public SortableIntArray(int [] data){
this.data = data;
}
public void Swap (int index1, int index2){
Integer x = data[index1];
data[index1] = data[index2];
data[index2]= x;
}
public int compare(int index1, int index2){
return data[index1]- data[index2];
}
public int size() {
return data.length;
}
}
package fr.univamu.sorting;
import java.util.List;
public class SortableIntList {
private List<Integer> data;
public SortableIntList(List<Integer> data){
this.data = data;
}
public void Swap (int index1, int index2){
Integer x = data.get(index1);
data.set(index1, data.get(index2));
data.set(index2, x);
}
public int compare(int index1, int index2){
return data.get(index1)- data.get(index2);
}
public int size(){
return data.size();
}
public int get(int index){
return data.get(index);
}
public void sort(){
bubbleSort();
}
public void bubbleSort(){
for( int i=0; i< data.size()-1; i++){
for(int j=0 ; j< data.size()-1-i; j++){
if(compare(j,j+1)>0){
Swap(j,j+1);
}
}
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment