当前位置:网站首页>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 ...
边栏推荐
- npm ERR Fix the upstream dependency conflict, or retry
- (solved) latex -- cancel the superscript display of references in the text (gbt7714-2015 will lead to the default superscript reference) (tutorial on mixed use of superscript and flush)
- Me11/me12 purchase information record and condition record creation and update bapi:me_ INFORECORD_ MAINTAIN_ MULTI
- Elsevier ---elseviewer--- preprint online publishing notice
- ACM教程 - 堆排序
- SAP smartforms page feed printing automatic judgment
- Task03: building an offline material system
- 【Qt】error: QApplication: No such file or directory 解决方案
- Within one month, the broadcasting volume has increased by 9million, and station B has three traffic growth passwords!
- 【MATLAB】图像分割
猜你喜欢

腾讯面试官曰Mysql架构的内部模块索引原理及性能优化思路谁会?

Complete tutorial on obtaining voltage from QGC ground station (APM voltage cannot be obtained from QGC)
![[leetcode] same tree + symmetric binary tree](/img/e5/40803ce66756c03737aa8991f7ec92.jpg)
[leetcode] same tree + symmetric binary tree

Interviewer: let me introduce the items in your resume. Tell me more about them, and attach the actual project
![[leetcode] path sum II (first glimpse recursion + backtracking)](/img/a8/54920e54a026ebef3eb0a1336e5b62.jpg)
[leetcode] path sum II (first glimpse recursion + backtracking)

CRS-4544 & ORA-09925
![[leetcode] flat multi-level bidirectional linked list](/img/7b/1631162f11a05e9323dd544fee6045.jpg)
[leetcode] flat multi-level bidirectional linked list

adb 常用命令解析
![[leetcode] ordered linked list transformation binary search tree](/img/9f/86e819beb8dc678d79c3e307891402.jpg)
[leetcode] ordered linked list transformation binary search tree

SAP smartforms text content manual wrap output
随机推荐
Within one month, the broadcasting volume has increased by 9million, and station B has three traffic growth passwords!
Introduction and practice of QT tcp/udp network protocol (supplementary)
【圖像處理】基於matlab GUI多功能圖像處理系統【含Matlab源碼 1876期】
[leetcode] balanced binary tree
[music] playing blue and white porcelain based on MATLAB [including Matlab source code 1873]
[leetcode] path sum II (first glimpse recursion + backtracking)
[traitement d'image] système multifonctionnel de traitement d'image basé sur l'interface graphique MATLAB [y compris le code source MATLAB 1876]
27岁女生零基础转行软件测试,合适吗?
接口自动化核心知识点浓缩,为面试加分
Coordinates of the capital of each province in China
The female programmer gives out a salary slip: the salary is high, but she feels she is 10 years old
ABAP CDS实现多行字段内容拼接
[leetcode] restore binary search tree
Complete tutorial on obtaining voltage from QGC ground station (APM voltage cannot be obtained from QGC)
Initialize the one-dimensional array a correctly
[matlab] image enhancement (power transformation, histogram specification processing method, smoothing and sharpening filtering)
腾讯测试开发岗面试上机编程题
Md61 plan independent demand import Bapi [by daily dimension / dynamic template / dynamic field]
【MATLAB】图像压缩编码(DCT、RLE)
[matlab] basic operation of MATLAB image processing