Skip to content
Snippets Groups Projects
Commit bc6aaf72 authored by t19015527's avatar t19015527
Browse files

mon TP après la scéance

parent 7e58a2d5
Branches
No related tags found
No related merge requests found
Pipeline #12414 failed
......@@ -12,6 +12,7 @@ public class App {
.map(String::valueOf)
.collect(Collectors.joining(",","[","]"))
);
System.exit(0);
}
}
package fr.univamu.sorting;
import java.util.List;
public interface Sortable {
int get(int index);
int size();
void swap(int index1, int index2);
int compare(int index1, int index2);
}
package fr.univamu.sorting;
public class SortableIntArray implements Sortable {
private int[] Array;
public SortableIntArray(int [] Array){
this.Array=Array;
}
public int[] GetArray(){
return this.Array;
}
public int size(){
return this.Array.length;
}
public int get(int index){
return this.Array[index];
}
public void swap(int index1, int index2){
int a = this.Array[index1];
int b = this.Array[index2];
this.Array[index1] = b;
this.Array[index2] = a;
}
public int compare(int index1, int index2){
return this.Array[index1]-this.Array[index2];
}
}
package fr.univamu.sorting;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
public class SortableIntList implements Sortable {
private List<Integer> list;
public SortableIntList(List<Integer> list){
this.list = list;
}
public List<Integer> GetList(){
return this.list;
}
public int get(int index){
return this.list.get(index);
}
public int size(){
return this.list.size();
}
public void swap(int index1, int index2){
int a = this.list.get(index1);
int b = this.list.get(index2);
this.list.add(index2,a);
this.list.add(index1,b);
}
public int compare(int index1, int index2){
return this.list.get(index1)-this.list.get(index2);
}
}
package fr.univamu.sorting;
public class insertionSort {
private Sortable Mustsort;
public insertionSort(Sortable Mustsort){
this.Mustsort = Mustsort;
}
public Sortable GetSortable(){
return this.Mustsort;
}
public void sort() {
int i = 0;
while (i<Mustsort.size()-1){
int x = Mustsort.get(i);
}
}
}
package fr.univamu.sorting;
import java.util.List;
public class quicksortSort {
private Sortable Mustsort;
public quicksortSort(Sortable Mustsort){
this.Mustsort = Mustsort;
}
public Sortable GetSortable(){
return this.Mustsort;
}
private List<List<Integer>> split(List<Integer> Tosplit){
int a = Tosplit.get(Tosplit.size()-1);
List<Integer> A = List.of();
List<Integer> B = List.of();
List<Integer> C = List.of();
for(int b : Tosplit){
if (a>b){
A.add(b);
}
if (a==b){
C.add(b);
}
if (a<b){
B.add(b);
}
}
return List.of(A,C,B);
}
private boolean HasRightSize(List<List<Integer>> Tocheck){
boolean Truth = true;
for (List<Integer> L : Tocheck){
if (L.size()>1){
Truth = false;
}
}
return Truth;
}
private List<Integer> Tolist(Sortable S){
int A = 0;
List<Integer> list = List.of();
while (A<S.size()){
list.add(S.get(A));
A=A+1;
}
return list;
}
private void Change(List<Integer> list){
int A = 0;
while (A<list.size()){
int B = 0;
while (B<this.Mustsort.size()){
if (this.Mustsort.get(B) == list.get(A)){
this.Mustsort.swap(B, A);
B=B+1;
}
}
A=A+1;
}
}
public void sort() {
List<Integer> Tosort = Tolist(this.Mustsort);
List<List<Integer>> Part = List.of(Tosort);
boolean Issort = false;
while (Issort == false){
List<List<Integer>> Provpart = List.of();
for (List<Integer> L : Part){
Provpart.addAll(split(L));
}
Part=Provpart;
Issort=HasRightSize(Part);
}
List<Integer> sort=List.of();
for (List<Integer> L : Part){
sort.addAll(L);
}
Change(sort);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment