7-7 create a binary tree for pre order sequence, output pre order sequence, middle order sequence and post order sequence, and output the number of leaf nodes (20 points)

I feel that I haven't learned the part of the tree very well. PTA encountered this problem and didn't write it out at first. After writing it, I found that it's actually very simple. Record it. In fact, what I learned is the process of writing this question That is, if you modify a structure with typedef, you can't define the structure variab ...

Posted by webosb on Thu, 10 Mar 2022 14:33:12 +0100

Preorder traversal of leetcode 144 binary tree

Preorder traversal of binary tree Title Description Give you the root node of the binary tree, root, and return the preorder traversal of its node value. Example 1: Input: root = [1,null,2,3] Output:[1,2,3] Example 2: Input: root = [] Output:[] Example 3: Input: root = [1] Output:[1] Method 1: recursion For tree traversal, recursive method ...

Posted by Kaizard on Wed, 09 Mar 2022 08:42:32 +0100

Binary tree data structure

Binary tree data structure A tree whose element has at most 2 children is called a binary tree. Because each element in a binary tree can only have two children, we usually name them left and right children. The binary tree node contains the following parts. dataPointer to left childPointer to the right child Binary tree includes: Full bi ...

Posted by phorman on Fri, 04 Mar 2022 11:57:41 +0100

Heap topK problem heap sorting priority queue object comparison problem

Heap topK problem - heap sorting The concept of heap ❓ To represent a binary tree with the child's representation (a common representation for brushing questions) is essentially a chain storage. In fact, there is also a sequential storage for the storage of binary trees. To put it bluntly, take an array to store a binary tree, and the way to ...

Posted by wendymelon on Thu, 03 Mar 2022 12:01:02 +0100

CSP2020-J-T3-expression

See you on the topic [CSP-J2020] expression - LuoguKnowledge point analysis: Be able to parse the specified data in the string. This topic requires to parse numbers and logical operators from the string. For ex amp le, x123 only resolves 123 and records it as the 123rd variable. For the convenience of storage, you can save &, |,! Save as a ...

Posted by Calamity-Clare on Thu, 24 Feb 2022 01:49:56 +0100

[binary tree] Morris traversal -- an traversal method without auxiliary space

preface Traversal of binary tree is an unavoidable problem to solve the related problems of binary tree. Many problems are solved on the basis of traversal. According to different problems, we can use different traversal methods. According to the order of operations on the root node, it can be divided into: Preorder traversal Middle order tra ...

Posted by md7dani on Tue, 22 Feb 2022 09:55:53 +0100

UVA122 traverses Trees on the level

Title Description input (11,LL) (7,LLL) (8,R) (5,) (4,L) (13,RL) (2,LLR) (1,RRR) (4,RR) () (3,L) (4,R) () output 5 4 8 11 13 4 7 2 1 not complete Idea 1: implement binary tree in pointer mode (chain storage) First define a structure, and then define a structure pointer root as the root node of the whole tree. If the left and right nodes ...

Posted by henrygao on Sat, 19 Feb 2022 13:08:37 +0100

Recursive traversal and iterative traversal of binary tree

Binary tree The so-called traversal refers to one and only one visit to each node in the tree along a search route. The operation of the access node depends on the specific application problem (for example, print the node content and add 1 to the node content). Traversal is one of the most important operations on a binary tree. It is a bin ...

Posted by mikegzarejoyce on Fri, 11 Feb 2022 14:49:31 +0100

Interviewer: you don't even know how to restore the binary tree?

Recover the binary tree according to traversal In the knowledge of binary tree, finding or traversing binary tree is a very important knowledge point. Because the author only paid attention to the traversal process of binary tree before, but ignored the importance of the inverse process of recovering binary tree from traversal. When I saw an a ...

Posted by jarriola on Tue, 08 Feb 2022 10:29:10 +0100

[sword finger Offer] personal learning notes_ 68_ Nearest common ancestor of binary search tree

Brushing date: 7:49 am Sunday, May 30, 2021 Personal question brushing records and code collection are all from leetcode After much discussion and consultation, we now intend to work in the direction of Java The main answer language is Java Title: Sword finger Offer 68 - I. nearest common ancestor of binary search tree Simple d ...

Posted by npsari on Tue, 08 Feb 2022 02:50:43 +0100