当前位置:网站首页>[JS] - [tree] - learning notes
[JS] - [tree] - learning notes
2022-06-24 23:17:00 【Interesting learning】
【js】-【 Tree Foundation 】- Learning notes
Statement : This note is based on the Nuggets brochure , If you want to learn more details , Please move https://juejin.cn/book/6844733800300150797
1 Binary tree
stay JS in , Binary trees use objects to define . Its structure is divided into three parts :
Data fields
Left child node ( The root node of the left subtree ) References to
Right child node ( The root node of the right subtree ) References to
- Define a binary tree constructor
// The constructor of a binary tree node
function TreeNode(val) {
this.val = val;
this.left = this.right = null;
}
- Create a new binary tree node
const node = new TreeNode(1)
1.1 The first sequence traversal
// The input parameters of all traversal functions are the root node objects of the tree
function preorder(root) {
# Recursive boundary ,root It's empty
if(!root) {
return
}
# Output the current traversal node value
console.log(' The node value currently traversed is :', root.val)
// Recursively traverses the left subtree
preorder(root.left)
// Recursively traverses the right subtree
preorder(root.right)
}
1.2 In the sequence traversal
# The input parameters of all traversal functions are the root node objects of the tree
function inorder(root) {
// Recursive boundary ,root It's empty
if(!root) {
return
}
// Recursively traverses the left subtree
inorder(root.left)
// Output the current traversal node value
console.log(' The node value currently traversed is :', root.val)
// Recursively traverses the right subtree
inorder(root.right)
}
1.3 After the sequence traversal
function postorder(root) {
// Recursive boundary ,root It's empty
if(!root) {
return
}
// Recursively traverses the left subtree
postorder(root.left)
// Recursively traverses the right subtree
postorder(root.right)
// Output the current traversal node value
console.log(' The node value currently traversed is :', root.val)
}
边栏推荐
- Selection (027) - what is the output of the following code?
- Research and investment strategy report on China's bridge anticorrosive coating industry (2022 Edition)
- 关于某手滑块的一些更新(6-18,js逆向)
- No main manifest attribute in jar
- Financial management [3]
- Accounting standards for business enterprises application [5]
- 慕思股份深交所上市:靠床垫和“洋老头”走红 市值224亿
- What kind of processor architecture is ARM architecture?
- 【js】-【数组、栈、队列、链表基础】-笔记
- Laravel scheduled task
猜你喜欢
15 lines of code using mathematical formulas in wangeditor V5

【js】-【字符串-应用】- 学习笔记

Pousser l'information au format markdown vers le robot nail

非单文件组件

03_ Spingboot core profile

laravel 宝塔安全配置

Installation and deployment of ganglia

The extra points and sharp tools are worthy of the trust | know that Chuangyu won the letter of thanks from the defense side of the attack and defense drill!

Attention, postgraduate candidates! They are the easiest scams to get caught during the preparation period?!

【js】-【数组、栈、队列、链表基础】-笔记
随机推荐
Docker-mysql8-master-slave
Laravel message queue
Epics record reference 4 -- fields for all input records and fields for all output records
InnoDB, the storage engine of MySQL Architecture Principle_ Redo log and binlog
[JS] - [array, Stack, queue, Link List basis] - Notes
Simulated 100 questions and online simulated examination of high voltage electrician examination in 2022
[ROS play with turtle turtle]
UNION ALL UNION FULL JOIN
docker-mysql8-主从
01_SpingBoot 框架入门
Research and investment strategy report on China's bridge anticorrosive coating industry (2022 Edition)
Building Survey [3]
Non single file component
15 lines of code using mathematical formulas in wangeditor V5
Laravel scheduled task
Gocolly manual
【js】-【数组、栈、队列、链表基础】-笔记
Push markdown format information to the nailing robot
Tech talk activity review kubernetes skills of cloud native Devops
Écoutez le fichier markdown et mettez à jour Hot next. Page JS
