Skip to content
Snippets Groups Projects
Commit d0ce822b authored by vincent.steinman's avatar vincent.steinman
Browse files

End section 1

parent 5d244ab2
No related branches found
No related tags found
No related merge requests found
......@@ -182,17 +182,23 @@ public class Main {
}
public static void OrderArray(){
int size_array = contactArray.length;
Contact[] newContactArray = new Contact[size_array];
for(int i = 0; i < size_array -1; i++){
int test = contactArray[i].getPers().getFirst_name().compareTo(contactArray[i + 1].getPers().getFirst_name());
if(test < 0){
newContactArray[i] = contactArray[i+1];
newContactArray[i+1] = contactArray[i];
}
else{
newContactArray[i] = contactArray[i];
if(size_array > 1){
Contact[] newContactArray = new Contact[size_array];
for(int i = 0; i < size_array - 1; i++){ //-1 as we check +1 later
String nameP1 = contactArray[i].getPers().getFirst_name();
String nameP2 = contactArray[i+1].getPers().getFirst_name();
int test = nameP1.compareTo(nameP2); //Return distance between 2 letter (f and a = -5 / a and b = 1)
if(test > 0){
newContactArray[i] = contactArray[i+1];
newContactArray[i+1] = contactArray[i];
}
else{
newContactArray[i] = contactArray[i];
}
if(i == size_array - 2){ //-2 to take last iteration only (as we do "i < size -1")
contactArray = newContactArray;
}
}
}
contactArray = newContactArray;
}
}
\ No newline at end of file
No preview for this file type
No preview for this file type
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment