first commit
This commit is contained in:
106
TP_DEV3.2/Genericite/Exotrois.java
Normal file
106
TP_DEV3.2/Genericite/Exotrois.java
Normal file
@@ -0,0 +1,106 @@
|
||||
public class Exotrois {
|
||||
|
||||
|
||||
public static <T> plusFrequent(T[] tableau){
|
||||
|
||||
|
||||
T valeurGagnante = tableau[0];
|
||||
int frequenceGagnante = 0;
|
||||
int premierIndexGagnant = tableau.length;
|
||||
|
||||
|
||||
|
||||
for(int i=0;i<tableau.length; i++){
|
||||
|
||||
|
||||
|
||||
T valeurCourante = tableau[i];
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int frequenceCourante =0;
|
||||
for(int k=0; k<tableau.length; k++){
|
||||
|
||||
if(Object.equals(tableau[k], valeurCourante)){
|
||||
|
||||
frequenceCourante++;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
int premierIndexCourant = -1;
|
||||
for(int j=0; j<tableau.length; j++){
|
||||
|
||||
if(Object.equals(tableau[j]), valeurCourante){
|
||||
|
||||
premierIndexCourant=j;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user