My code should merge two already sorted arraylists into one sorted arraylist and if one of the arraylists used is not sorted then it should return null.
public class MergeSorted {
public static void merge(ArrayList<Integer> a, ArrayList<Integer> b) {
for (int i = 0, j = 0; j < b.size(); i++) {
if (i == a.size() || a.get(i) > a.get(j)) {
a.add(i, b.get(j++));
}
}
}
}
This is what I attempted but can't get the idea of returning null if they are not equal, Im new to java and this is my second week so please be patient with me. I know I should have an if statement checking if they are sorted and an else but what should I include inside the if?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire