随笔分类 - 算法点滴
摘要:求斐波纳契数列第n个数的两种实现方法。 1 public class TestFibo { 2 3 public static void main(String[] args){ 4 System.out.println(f(7)); 5 System.out.println(fn(7)); 6 } 7 8 //递归实现 9 public static long f(int index){10 11 if(index<1){12 System.out.p...
阅读全文
摘要:用冒泡算法实现对日期的排序 1 //日期类,包含年月日的信息。重写toString 2 //方法,输出年月日信息。 3 public class Date { 4 5 public int year ,month,day; 6 7 public Date(int year,int month,int day){ 8 this.year = year; 9 this.month = month;10 this.day = day;11 }12 13 public String toString()...
阅读全文
摘要:二分查找的实现。算法要求1.必须采用顺序存储结构2.必须按关键字大小有序排列。算法复杂度为o(logn),一般只要被查找的元素大于或等于序列中的最大元素,算法总要执行最大次数的比较。对于一个大小为n的排序数组,算法BINARYSEARCH执行的比较的最大次数为[logn]+1。 1 public class BinarySearch { 2 3 public static int BinarySearchMethod(int[] before,int target){ 4 int low = 0,high = before.length - 1,mid = 0,j =...
阅读全文

浙公网安备 33010602011771号