I was wondering if anybody had any idea of how to quickly braid two arrays into one? Lets say there are two arrays like this:
String [ ] a1 = {"b","d","i","j","p","w","z"}
String [ ] a2 = {"a","c","e","f","h","q","r"}.
These are both sorted, but I want to merge them with a braiding
technique, so that it'll become one long sorted array.
This is my method so far, and it does not work, the tmp array ends up with just null
at it [x].
static void braid(String [] a, String[] b){
String [] tmp = new String [a.length+b.length];
for(int i = 0; i < a.length; i++){
for(int j = 0; j < b.length; j++){
if(a[i].compareTo(b[j]) < 0) tmp[i] = a[i];
else if(b[i].compareTo(a[j]) < 0) tmp[i] = b[i];
}
}
for(int i = 0; i < tmp.length;i++){
System.out.print(tmp[i] + "+");
}
System.out.println();
}