Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
Loading items

Target

Select target project
  • gnaves/sort-template
  • g21232913/sort-tp-6
  • t19015527/tp-6
  • f20021643/sort-template
  • a22027291/sort-salim
  • s19033421/sort-template
  • b21232450/sort-template
7 results
Select Git revision
Loading items
Show changes
......@@ -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);
}
}
}
}
}