Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

What is the middle order traversal of C++ LeeCode binary tree?

Shulou Source: shulou.com Published: 2022-05-31 13:55:19 09月30日 Update

This article mainly introduces the C++ LeeCode binary tree in the order of traversal is what the relevant knowledge, the content is detailed and easy to understand, simple and fast operation, with a certain reference value, I believe that you will gain after reading this C++ LeeCode binary tree in the order of what the article is, let's take a look.

I. title

II. Code

/ * Definition for a binary tree node. * struct TreeNode {* int val; * TreeNode * left; * TreeNode * right; * TreeNode (): val (0), left (nullptr), right (nullptr) {} * TreeNode (int x): val (x), left (nullptr), right (nullptr) {} * TreeNode (int x, TreeNode * left, TreeNode * right): val (x), left (left), right (right) {} *} * / class Solution {public: void Middle (TreeNode* root,vector & num) {/ / Central order traversal, left-root-right if (! root) {/ / current node is empty return;} Middle (root- > left,num); / / left num.push_back (root- > val); / / Root Middle (root- > right,num) / / right} vector inorderTraversal (TreeNode* root) {/ / because no vector container parameter is passed, you need to use a new function to traverse the binary tree to store the result in vector and return the vector num;// storage traversal result Middle (root,num); / / Recursive implementation traverses the binary tree return num;}} This is the end of the article on "what is the middle order traversal of C++ LeeCode binary tree?" Thank you for reading! I believe you all have a certain understanding of the knowledge of "what is the middle order traversal of C++ LeeCode binary tree". If you want to learn more knowledge, you are welcome to follow the industry information channel.

Tags: Clips knowledge content articles results codes values functions parameters containers easy to operate articles easy to understand more look nodes industries information channels channels Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple Redmi Shulou Information NVidia MySQL