摘要:
1.直接选择算法
1 // 直接选择排序
2 //Code by Larman Yuan 2009-06-29 阅读全文
摘要:
huffman算法即最优二叉树的实现:(其中用到的堆栈算法在前面的文章中以列出)Code[代码]121运行结果为:Eoncode for W 2 is: 1 0 1 1 1 1 0Eoncode for W 3 is: 1 0 1 1 1 1 1Eoncode for W 5 is: 1 0 1 1 1 0Eoncode for W 7 is: 1 0 1 1 0Eoncode for W 11 ... 阅读全文
摘要:
[代码]运行结果:The reverse path is:The location is: 15The location is: 6The location is: 14The location is: 2The location is: 11The location is: 1The location is: 9The location is: 0 阅读全文
摘要:
算法:(此算法来自于<<算法与数据结构-C语言描述>>张乃孝 主编, 但书中的代码有错误,红色部分为修正部分,与各位看官共勉)[代码]运行结果:The reverse path is:the node is:(6 9)the node is:(6 8)the node is:(6 7)the node is:(6 6)the node is:(6 5)the node is... 阅读全文
摘要:
简单背包问题:有一个背包,能盛放的物品总重量为s,设有n件物品,其重量分别为w1,w2,...,wn.希望从N件物品中选择若干件物品,所选物品的重量之和恰能放入该背包,即所选物品的重量之和等于s。递归算法:[代码]运行结果:result: n = 1, w[0] = 1result: n = 3, w[2] = 4result: n = 4, w[3] = 5非递归算法:(参考http://blo... 阅读全文
摘要:
没啥好说的,理解代码是王道[代码] 运行结果: Location is: 6 阅读全文
摘要:
一直觉得数据结构是很好的东西,早就说要看,直到现在才静下心来。下面就从简单的线性表开始,慢慢学习吧。线性表综合运用:约瑟夫循环:设有n个人围坐在一个圆桌周围,现在从第s个人开始报数,数到第m的人出列,然后从出列的人下一个人重新开始报数,数到第m的人出列......如此反复直到所有的人全部出列为止。约瑟夫循环问题是:对于任意给定的n,s和m,求出按出列次序得到的n个人员的序列。1.顺表表实现(数组)... 阅读全文
摘要:
1.catch子句按照筛选器的继承层次进行顺序罗列,否则将导致编译错误 示例: Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ -->1usingSystem; 2usingSystem.Collections.Generic; ... 阅读全文
摘要:
问题思考: 如果在父类class Base的非虚方法public A()中调用了虚方法B(),而在子类class Derived中重写了该虚方法,那么Derived.A()中调用的是虚函数父类中的实现还是子类中的实现? 结论:子类中的实现。 实例证明: Code Code highlighting produced by Actipro CodeHighlighter (free... 阅读全文