摘要: public class Fibonacci{ public static void main(String args[]){ int nums = fibonacci(8); System.out.println(nums); } static int fibonacci(int n){ if(n<=1) return 1; return fibonacci(n-1)+fibonacci(n-2); } } 阅读全文
posted @ 2011-03-10 23:02 魔战 阅读(210) 评论(0) 推荐(0) 编辑
摘要: /** * @author @liugang* 快排的算法* @param pData 需要排序的数组 * @param left 左边的位置,初始值为0 * @param right 右边的位置,初始值为数组长度 * 选择数组中的一个元素作为标准,将所有比标准小的元素放到左边,* 所有比标准大的元素放到右边。* 并对左边和右边的元素做一样的快速排序过程。*/ public class Qsort { public static void QuickSort(int[] pData, int left, int right) { int i, j; int k = 0; int middle, 阅读全文
posted @ 2011-03-10 22:37 魔战 阅读(250) 评论(0) 推荐(0) 编辑
摘要: /*** @author @liugang* 简单选择排序的思想* 每遍历未排序部分一次都产生一个最小值,并将最小值移到数组的前端*/public class Simpleselectionsort { private static int count = 0; public static void printAll(int[] a) { System.out.println("第" + (++count) + "次:"); for (int i = 0; i < a.length; i++) { System.out.print(a[i] + & 阅读全文
posted @ 2011-03-10 22:32 魔战 阅读(243) 评论(0) 推荐(0) 编辑
摘要: /*** @author @liugang*插入排序的思想*从第二个元素开始,因为左侧的数组为排序后的数组,*只要将当前元素插入到左侧数组的适当位置,就能保持数组为有序*然后处理第三个元素...直到最后一个元素*/public class Insertsort { private static int count = 0; public static void printAll(int[] a) { System.out.println("第" + (++count) + "次:"); for (int i = 0; i < a.length; i 阅读全文
posted @ 2011-03-10 22:14 魔战 阅读(210) 评论(0) 推荐(0) 编辑
摘要: /*** @author Administrator* 冒泡排序的算法* 比较n轮,每一轮都把最大元素移动到数组后端*/public class Maopaosort { private static int count = 0; public static void Sort(int[] a) { int temp = 0; int i = 0, j = 0; for (i = 1; i < a.length; i++) { //找到最大值 for (j = 0; j < a.length - i; j++) { if (a[j] > a[j + 1]) { // 这里的“ 阅读全文
posted @ 2011-03-10 21:48 魔战 阅读(164) 评论(0) 推荐(0) 编辑