Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

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

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report