当前位置:网站首页>Day code 300 lines learning notes day 22
Day code 300 lines learning notes day 22
2022-06-11 02:09:00 【Leeyz_ one】
1. Binary tree storage
Code :
package tree;
import java.util.Arrays;
import tree.BinaryCharTree;
public class CircleObjectQueue2 {
// The node value obtained by breadth first traversal
char[] valuesArray;
// Index of complete binary tree
int[] indicesArray;
// Convert tree to data array , Including a char Array and a int Array . The results are stored in two member variables .
public void toDataArrays() {
// Initialize array ????
/*int tempLength = getNumNodes();
valuesArray = new char[tempLength];
indicesArray = new int[tempLength];
int i = 0;
*/
// Traversal and transformation at the same time
CircleObjectQueue tempQueue = new CircleObjectQueue();// Instantiation
tempQueue.enqueue(this);// The team
CircleIntQueue tempIntQueue = new CircleIntQueue();
tempIntQueue.enqueue(0);// The team
/*
* ??????????????
*/
BinaryCharTree tempTree = (BinaryCharTree) tempQueue.dequeue();
int tempIndex = tempIntQueue.dequeue();
while (tempTree != null) {
valuesArray[i] = tempTree.value;
indicesArray[i] = tempIndex;
i++;
if (tempTree.leftChild != null) {
tempQueue.enqueue(tempTree.leftChild);
tempIntQueue.enqueue(tempIndex * 2 + 1);
} // Of if
if (tempTree.rightChild != null) {
tempQueue.enqueue(tempTree.rightChild);
tempIntQueue.enqueue(tempIndex * 2 + 2);
} // Of if
tempTree = (BinaryCharTree) tempQueue.dequeue();
tempIndex = tempIntQueue.dequeue();
} // Of while
}// Of toDataArrays
// main
public static void main(String args[]) {
// CircleObjectQueue tempQueue = new CircleObjectQueue();
BinaryCharTree tempTree = BinaryCharTree.manualConstructTree();
System.out.println("\r\nPreorder visit:");
tempTree.preOrderVisit();
System.out.println("\r\nIn-order visit:");
tempTree.inOrderVisit();
System.out.println("\r\nPost-order visit:");
tempTree.postOrderVisit();
System.out.println("\r\n\r\nThe depth is: " + tempTree.getDepth());
System.out.println("The number of nodes is: " + tempTree.getNumNodes());
tempTree.toDataArrays();
System.out.println("The values are: " + Arrays.toString(tempTree.valuesArray));
System.out.println("The indices are: " + Arrays.toString(tempTree.indicesArray));
}// Of main
}
2. summary
People are confused , There was a problem in calling functions of other classes , for example 56 In line , The source code is not added to the right BinaryCharTree Name of class , If you don't add... To the right of the equal sign BinaryCharTree The name of this class , An error will be reported if this function is not defined . Another example is 16 Row initializing array ,18 It seems that whether the line is not running or not will not affect the final result ? Because this line calls getNumNodes When this function , There are also some problems , It is also shown in CircleObjectQueue2 This function is not defined in this class . Today, I will focus on the code , Calling functions in other classes is not very clear , Some can be called successfully , Some calls are unsuccessful , Add the calculation traversal and numbering , Stupid ... If you say will 22 The code of the day , Just put it all in 21 Days of code , It can also be run directly , After all, all the functions it calls are 21 Created within days ...
边栏推荐
- [untitled]
- ---排列数字---
- [matlab] image enhancement (power transformation, histogram specification processing method, smoothing and sharpening filtering)
- CRS-5017
- Internet of things final assignment - sleep quality detection system (refined version)
- 面试官:介绍一下你简历中的项目,细讲一点,附项目实战
- Data and electricity course design: circuit of full adder / subtractor
- 27岁女生零基础转行软件测试,合适吗?
- Oracle收集统计信息
- The female programmer gives out a salary slip: the salary is high, but she feels she is 10 years old
猜你喜欢

Method of using dism command to backup driver in win11 system
![[traffic sign recognition] Based on Matlab GUI YCbCr feature extraction +bp neural network traffic sign recognition [including Matlab source code 1869]](/img/66/3f7134298e7e9a7fbf9b0c99dafb2a.jpg)
[traffic sign recognition] Based on Matlab GUI YCbCr feature extraction +bp neural network traffic sign recognition [including Matlab source code 1869]

记录一下我的刷题实录

Virtual joystick of QT quick QML instance

Task02: basic use of database (MySQL)
![Md61 plan independent demand import Bapi [by daily dimension / dynamic template / dynamic field]](/img/28/2a4fd7f019f6528bd322c5e75ecaa7.png)
Md61 plan independent demand import Bapi [by daily dimension / dynamic template / dynamic field]

Introduction and practice of QT tcp/udp network protocol (I) TCP communication

QT widget's simple serial port assistant (qserialport)

Secret

Win11触摸键盘主题如何更换?Win11更换触摸键盘主题的方法
随机推荐
Question g: candy
【MATLAB】图像压缩编码(DCT、RLE)
How to reinstall win11 drawing tool when it is missing
CRS-4544 & ORA-09925
Database overview
【MATLAB】MATLAB图像处理基本操作
【MATLAB】图像复原
[leetcode] different binary search trees (recursion - recursion + memory search optimization - dynamic programming)
[leetcode] same tree + symmetric binary tree
基于Gin、Gorm实现的在线练习系统之项目梳理
Win11画图工具没了怎么重新安装
Treatment of small fish
[BSP video tutorial] BSP video tutorial issue 17: single chip microcomputer bootloader topic, startup, jump configuration and various usage of debugging and downloading (2022-06-10)
Method of using dism command to backup driver in win11 system
Using an old mobile phone to build a server and achieve intranet penetration does not require root (I have personally tested the simplest one many times)
Today's sleep quality record 80 points
Shell learning tutorial (super detailed and complete)
Within one month, the broadcasting volume has increased by 9million, and station B has three traffic growth passwords!
Well paid test development programmers, why are you leaving? Kill each other with products until the sky is dark
[leetcode] LRU cache