一个面试的排序题
坛子里一个哥们的面试题:
public class test {public static int[] b = { 1, 3, 5, 7, 9, 10, 11, 90 };public static int[] a = { 2, 5, 7, 8, 9 };public static void main(String[] args) {test1(a,b);Map<Integer,Integer> map=sortByTreeMap(a,b);Iterator iterator = map.entrySet().iterator();while (iterator.hasNext()) { Map.Entry mapentry = (Map.Entry)iterator.next(); System.out.print(mapentry.getValue()+" ");}}public static void test1(int[] a, int[] b){int[] c = new int[a.length + b.length];int i = 0, j = 0, k = 0;while (i < a.length && j < b.length) {if (a[i] <= b[j]) {if (a[i] == b[j]) {j++;} else {c[k] = a[i];i++;k++;}} else {c[k] = b[j];j++;k++;}}while (i < a.length) {c[k] = a[i];k++;i++;}while (j < b.length) {c[k] = b[j];j++;k++;}System.out.println(Arrays.toString(c));}public static Map sortByTreeMap(int[] a, int[] b){ Map<Integer,Integer> map=new TreeMap<Integer,Integer>(); for(int i=0;i<a.length;i++){ map.put(a[i], a[i]); } for(int i=0;i<b.length;i++){ map.put(b[i], b[i]); } return map;}}
??
$b = array(1, 3, 5, 7, 9, 10, 11, 90 );$a = array( 2, 5, 7, 8, 9);print_r($a+$b);