Tag:Preorder

  • Leetcode PHP题解–D130 257. Binary Tree Paths

    Time:2022-8-26

    D130 257. Binary Tree Paths topic link 257. Binary Tree Paths topic analysis Given a binary tree, return the paths of all child nodes. Problem solving ideas This question doesn't seem to be difficult. While pre-order traversal, the collection of parent nodes is stuffed into an array. When the current node is a leaf node, […]

  • [NOIP2001 Popularization Group] Seek Ranking

    Time:2022-8-15

    Question analysis: The question mentions the pre-order, in-order, and post-order arrangement of trees, so we need to know what these three arrangements mean first. 3 (depth-first) permutations of binary trees: Pre-order, "root left and right". That is, for each subtree of the binary tree, first visit its root, and then traverse its left and right […]

  • Binary tree

    Time:2022-5-1

    Normal tree building and traversal Preorder traversal void Pre(node *F){ if(!F)return; cout<value; Pre(F->L); Pre(F->R); } code /** *Input format: abc##de#g##f### **/ #include using namespace std; //Define chain tree struct btnode { char value; btnode *lc; btnode *rc; }; //Pre order tree building void build(btnode *&F) { char ch; cin>>ch; if(ch==’#’) F=NULL; else { F=new btnode; […]

  • Binary tree related processing, including recursive and non recursive methods

    Time:2022-3-28

    1. Introduction Be familiar with various characteristics of binary tree, including pre order, middle order, post order traversal, restoring binary tree and so on Mainly collected recursive and non recursive schemes, which can be compared and studied Learning this is also to brush questions on leetcode The following program running results {1 {2 {0 {3 […]

  • Serialization and deserialization of binary tree

    Time:2022-3-2

    Definition of serialization: Serialization refers to the process of converting the data structure or object state into a usable format (such as saving it as a file, buffering it, or sending it through the network) for later recovery in the same or another computer environment. When the byte result is retrieved according to the serialization […]

  • Java implementation of child brother tree

    Time:2022-2-7

    Java implementation of child brother tree 1. Data definition The definition structure of specific child brother tree will not be repeated. @Data @NoArgsConstructor @AllArgsConstructor public class TreeNode { private String value; private TreeNode childNode; private TreeNode broNode; public TreeNode(String value){ this.value = value; } } 2. Implementation of tree @Slf4j public class TreeUtils { /** […]

  • Establish binary linked list in first order and traverse in first order, middle order and then order (recursion)

    Time:2022-1-6

    #include<iostream> using namespace std; typedef struct BiNode{ char data; struct BiNode *lchild,*rchild; }BiTNode,*BiTree; //Establish binary linked list first void CreateBiTree(BiTree &T){ char ch; cin >> ch; if(ch==’#’) T=NULL; else{ T=new BiTNode; T->data=ch; CreateBiTree(T->lchild); CreateBiTree(T->rchild); } } //Preorder traversal void Pre(BiTree T){ if(T){ cout<<T->data; Pre(T->lchild); Pre(T->rchild); } } //Medium order traversal void In(BiTree T){ if(T){ In(T->lchild); […]

  • Establish binary linked list and traversal in preorder (chain stack non recursive)

    Time:2022-1-5

    #include<iostream> using namespace std; typedef struct BiNode{ char data; struct BiNode *lchild,*rchild; }BiTNode,*BiTree; //Establish binary linked list first void CreateBiTree(BiTree &T){ char ch; cin >> ch; if(ch==’#’) T=NULL; else{ T=new BiTNode; T->data=ch; CreateBiTree(T->lchild); CreateBiTree(T->rchild); } } //Chain stack typedef struct StackNode{ BiTNode data; struct StackNode *next; }StackNode,*LinkStack; //Construct empty stack s void InitStack(LinkStack &S){ S=NULL; […]

  • Command line print file tree list: tree

    Time:2021-10-18

    Linux & Mac 1. Downloadtree lib //mac brew install tree //centos yum install tree //ubuntu apt-get install tree usage //Show all files tree //Display depth 2 layers tree -L 2 2. Command find combination find . -print | sed -e ‘s;[^/]*/;|____;g;s;____|; |;g’ > structure.txt Remove node_ module find . -print | grep -v “node” | […]

  • [PHP data structure] traversal and logical operation of binary tree

    Time:2021-10-14

    In the last article, we talked about a lot of theoretical knowledge. Although it is very boring, those are the premise of our study today. When you look at the code later, you will find how important these theoretical knowledge is. First of all, we still want to explain that the main content of our […]

  • PAT A1043 Is It a Binary Search Tree

    Time:2021-10-4

    Pat a1043 is it a binary search tree (25 points) A Binary Search Tree (BST) is recursively defined as a binary tree which has the following properties: The left subtree of a node contains only nodes with keys less than the node’s key. The right subtree of a node contains only nodes with keys greater […]

  • [tree topics] binary tree Traversals

    Time:2021-8-22

    A binary tree is a finite set of vertices that is either empty or consists of a root r and two disjoint binary trees called the left and right subtrees. There are three most important ways in which the vertices of a binary tree can be systematically traversed or ordered. They are preorder, inorder and […]