typedef struct node { int data; struct node *link; }NODE; void reverse(NODE head) { NODE temp = null; NODE p = head->link; head->link = null;// 头结点变为尾结点 while(p!=null) { ...
public static void main(String[] args) { getDistinct(new int[] { 6, 7, 3, 6, 5, 2, 7, 8 }); } static void getDistinct(int array[]) { java.util.List list = new java.util.ArrayList(); for (int i = 0; i < array.length; i++) { if (!list.contains(array[i])) { list.add(array[ ...
2008-03-16

二叉树

public class Tree { private int data;// 数据节点 private Tree left;// 左子树 private Tree right;// 右子树 public Tree(int data) { this.data = data; this.left = null; this.right = null; } /** * 创建二叉树,返回根结点 * * @param input * @return */ public static Tree createTre ...
/** * 二分法查找 * 查找线性表必须是有序列表 * * @param e * @param key * @return */ public int binarySearch(int[] e, int key) { int low = 0, high = e.length - 1, mid; while (low <= high) { mid = (low + high) / 2; if (key == e[mid]) { return mid; } else if (key < ...
/** * 选择排序 总比较次数:n*(n-1)/2 不稳定排序 * * @param e */ public void chooseSort(int[] e) { int t; for (int i = 0; i < e.length - 1; i++) { for (int j = i + 1; j < e.length; j++) { if (e[i] > e[j]) { t = e[i]; e[i] = e[j]; e[j] = t; } } } ...
/** * 求两数最大公约数 * * @param a * @param b * @return */ int divisor(int a, int b) { if (a % b == 0) { return b; } else { return divisor(b, a % b); } } /** * 求两数最小公倍数 * * @param a * @param b * @return */ int multiple(int a, int b) { i ...
/** * N阶乘(递归) */ int result = 1; public int nFactorial(int n) { if (n > 0) { result = result * n; nFactorial(n - 1); } return result; }
/** * (转载) * @author blog4Leon * * 输入 * 1234 * 5678 * 90ab * cdef * 输出 * 12348bfedc9567a0 * * @param args */ public static void main(String[] args) { char[][] chars = { { '1', '2', '3', '4' }, { '5', '6', '7', '8' }, { '9', '0', ...
/** * 裴波那契数列(递归) * @param n * @return */ public int fib(int n) { if (n < 1) { return 0; } if (n == 1 || n == 2) { return 1; } return fib(n - 1) + fib(n - 2); }
/** * 字符串反转(栈) * * @param str * @return */ public String reverseStr(String str) { char[] stack = new char[str.length()];// 栈 // 进栈 for (int i = 0; i < str.length(); i++) { stack[i] = str.charAt(i); } // 出栈 StringBuffer reverseStr = new StringBuffer(""); ...
javaboy2006
搜索本博客
我的相册
A84ce64e-d101-3dad-9e62-8780e1c003ea-thumb
CommandPattern2
共 11 张
最近加入圈子
存档
最新评论