What is the middle order traversal of C++ LeeCode binary tree?
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.