2010年7月6日
摘要: public class Main { public static void main(String[] args) { int [] a = {2,4,5,7,8,6,10} ; pack(14,a,0,new int[a.length]); } private static void pack(int total,int [] src,int offset,int [] bag){ if (t... 阅读全文
posted @ 2010-07-06 23:32 sunliho 阅读(114) 评论(0) 推荐(0) 编辑
摘要: public class Main { public static void main(String[] args) { System.out.println(power(3,18)); } //求x的y次幂 private static long power(long x, long y){ if ( y == 1) return x ; else { if (y % 2 == 1) retur... 阅读全文
posted @ 2010-07-06 21:57 sunliho 阅读(254) 评论(0) 推荐(0) 编辑
摘要: 算法效率(O(N*LogN))优于冒泡,选择以及插入排序(O(N*N)),这里的实现效率不高,生成了大量临时数组,对于理解比较容易。public class Main { public static void main(String[] args) { int [] a = {9,8,7,6,5,4,3,2,1}; int [] b = mergeSort(a) ; for (int i:b) S... 阅读全文
posted @ 2010-07-06 05:40 sunliho 阅读(108) 评论(0) 推荐(0) 编辑
摘要: public class Main { public static void main(String[] args) { hanoi(4,'A','B','C'); } //将n个盘子从a经过b搬运到c上 private static void hanoi(int n, char a, char b , char c){ if ( n == 1) System.out.println(a + " ... 阅读全文
posted @ 2010-07-06 04:39 sunliho 阅读(169) 评论(0) 推荐(0) 编辑
摘要: public class Main { public static void main(String[] args) { System.out.println(common(25,100)); } private static int common(int m , int n){ if (m % n == 0) return n ; else return common(n,m%n); }}最小公... 阅读全文
posted @ 2010-07-06 00:25 sunliho 阅读(123) 评论(0) 推荐(0) 编辑
摘要: public class Main { private static char [] str = {'1','2','3','4'} ; public static void main(String[] args) { arrange(str.length); } private static void arrange(int size){ if (size == 1) { show(); ret... 阅读全文
posted @ 2010-07-06 00:17 sunliho 阅读(175) 评论(0) 推荐(0) 编辑
  2010年7月4日
摘要: public class Main { public static void main(String[] args) { int [] arr = {9,8,7,6,5,4,3,2,1,0}; insertSort(arr); for(int i:arr) System.out.println(i); } private static void insertSort(int [] arr){ fo... 阅读全文
posted @ 2010-07-04 23:23 sunliho 阅读(168) 评论(0) 推荐(0) 编辑
摘要: public class Main { public static void main(String[] args) { int [] arr = {9,8,7,6,5,4,3,2,1,0}; selectSort(arr); for(int i:arr) System.out.println(i); } private static void selectSort(int []arr){ for... 阅读全文
posted @ 2010-07-04 22:46 sunliho 阅读(196) 评论(0) 推荐(0) 编辑
摘要: public class Main { public static void main(String[] args) { int [] arr = {9,8,7,6,5,4,3,2,1,0}; bubbleSort(arr); for(int i:arr) System.out.println(i); } private static void bubbleSort(int [] arr){ fo... 阅读全文
posted @ 2010-07-04 22:34 sunliho 阅读(117) 评论(0) 推荐(0) 编辑
摘要: public class Main { public static void main(String[] args) { int[] a = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11}; int x = search(a, 12); System.out.println(x); } private static int search(int[] src, int val)... 阅读全文
posted @ 2010-07-04 09:37 sunliho 阅读(89) 评论(0) 推荐(0) 编辑