
java
月同学不写Bug
记录学习点滴
展开
-
霍夫曼树二叉树遍历:1.写在节点类中,在上层调用;2.写在主函数中一次性整体完成
1. 霍夫曼树整体的前序遍历public static void preHufOrder(Node node) { if (node != null) { //每次都会先判断当前节点是否为空,造成重复判断,可以在调用该函数时进行判断的方法进行改善 System.out.println(node); if (node.left != null) { preHufOrder(node.left); } if (原创 2022-04-28 14:56:00 · 198 阅读 · 0 评论 -
前序、中序、后序线索化二叉树,前序、中序、后序线索化二叉树遍历,《尚硅谷韩顺平数据结构与算法》课后习题(Java语言版本)
1.前序//前序线索化二叉树public void threadedPreNode(HeroNode node) { if (node == null) { return; } //线索化当前节点 if (node.getLeft() == null) { node.setLeft(pre); node.setLeftType(1); } if (pre != null && pre...原创 2022-04-27 19:53:50 · 335 阅读 · 0 评论 -
《尚硅谷韩顺平数据结构》课后作业,二叉树前序线索化与前序线索化遍历(Java语言版)
1.前序线索化与前序线索化遍历//前序线索化二叉树public void threadedPreNode(HeroNode node) { if (node == null) { return; } //线索化当前节点 if (node.getLeft() == null) { node.setLeft(pre); node.setLeftType(1); } if (pre != null &..原创 2022-04-27 18:42:41 · 1319 阅读 · 1 评论 -
《尚硅谷韩顺平数据结构》斐波那契查找,数组中元素个数的说明为F[k]-1
韩老师代码中数组中元素个数的说明为F[k],经过分析我们可以发现实际使用的只有F[k]-1,所以temp数组中元素个数为F[k]-1更为合理。查找过程如下图所示:public static int[] fib() { int[] f = new int[maxSize]; f[0] = 1; f[1] = 1; for (int i = 2; i < maxSize; i++) { f[i] = f[i - 1] + f[i - 2];原创 2022-04-24 20:56:46 · 408 阅读 · 1 评论 -
《尚硅谷韩顺平数据结构》单链表无顺序添加时,节点对象形成封闭环问题,无法添加同一个对象导致遍历输出时一直执行输出。
1.进行对象是否相同的判断。public void add(HeroNode heroNode) { //创建辅助节点 HeroNode temp = head; //遍历链表,找到最后 while (true) { if (temp.next == null) {// break; } //未到最后,将temp后移 temp = temp.next; } //当退原创 2022-04-19 16:03:41 · 471 阅读 · 0 评论