1 /** 2 * Definition for binary tree 3 * struct TreeNode { 4 * int val; 5 * TreeNode *left; 6 * TreeNode *right; 7 * TreeNode(int x) : val(x), left(NULL), right(NULL) {} 8 * }; 9 */10 class Solution {11 public:12 void preOr(TreeNode * node, vector & rlt){13 if (node==NULL)14 return;15 rlt.push_back(node->val);16 preOr(node->left,rlt);17 preOr(node->right,rlt);18 }19 vector preorderTraversal(TreeNode *root) {20 // IMPORTANT: Please reset any member data you declared, as21 // the same Solution instance will be reused for each test case.22 vector rlt;23 preOr(root, rlt);24 return rlt;25 }26 };