ITeye博客

qsslwyf的博客

qsslwyf · 共 4 篇文章

二叉树遍历递归和非递归算法总结

非原创,稍做总结,保存起来以便日后查看,希望能帮到大家。 import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.Stack; /** A BinaryTree consists of "nodes"--each "node" is itself a BinaryTree. Each node has a parent (unless it is the root), may have a left child, an…

2013-03-15 17:22 · 算法 · 评论(0)

最长子字符串问题-动态规划法

public class LCSProblem { public static void main(String args) { String x = {"","A", "B", "C", "B", "D", "A", "B"}; String y = {"","B", "D", "C", "A", "B", "A"}; char b = getLCSLength(x, y); display(b, x, x.length -1, y.length - 1); } //B C B A public static char getLCSLength(String x, String y) { …

2013-03-03 15:03 · 算法 · 评论(0)

背包算法--动态规划法

/************************************************************************* Compilation: javac Knapsack.java Execution: java Knapsack N W * Generates an instance of the 0/1 knapsack problem with N items and maximum weight W and solves it in time and space proportional to N * W using dynamic programm…

2013-03-03 14:51 · 算法 · 评论(0)

八皇后问题

class QueensApp { private int intArray; private int nElems; private int count; public QueensApp(int len) { intArray = new int; nElems = len; } public int getCount() { return this.count; } private boolean isConsistent(int n) { for(int i = 0; i < n; i++) { if (intArray* == intArray) return false; //s…

2013-03-02 12:22 · 算法 · 评论(0)