摘要:
/** description:层次遍历* writeby: nick* date: 2012-10-22 23:56*/#include <iostream>#include <queue>using namespace std;struct node{ int item; node *l, *r; node(int n) { item=n; l=0; r=0; }};typedef node *link;void traverse(link h, void visit(link)){ ... 阅读全文
摘要:
//这不是最有效的方法,但使用了标记为容易理解,记下/** description:树的遍历示例,非递归版本* 入栈顺序:* 前序: 右子树 - 左子树 - 当前节点* 中序: 右子树 - 当前节点 - 左子树* 后序: 当前节点 - 右子树 - 左子树** writeby: nick* date: 2012-10-22 23:56*/#include <iostream>#include <stack>using namespace s... 阅读全文
摘要:
/** description:树的遍历示例,递归* 访问顺序:* 前序: 当前节点 - 左子树 - 右子树* 中序: 左子树 - 当前节点 - 右子树* 后序: 左子树 - 右子树 - 当前节点** writeby: nick* date: 2012-10-22 23:56*/#include <iostream>using namespace std;struct node { int item; node *l, *r;... 阅读全文
摘要:
/** description:背包示例* 一个大小为17的背包,有5类不同大小与价值的物品,求使得背包中的物品价值最大的组合* item A B C D E* size 3 4 7 8 9* value 4 5 10 11 13** writeby: nick* date: 2012-10-22 23:56*/#include <iostream>#include... 阅读全文