首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 其他相关 >

一个口试的排序题

2012-11-09 
一个面试的排序题坛子里一个哥们的面试题:public class test {public static int[] b { 1, 3, 5, 7, 9,

一个面试的排序题

坛子里一个哥们的面试题:

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);

热点排行