/* struct TreeNode { int val; struct TreeNode *left; struct TreeNode *right; TreeNode(int x) : val(x), left(NULL), right(NULL) { } };*/ /* struct ListNode { int val; struct ListNode *next; ListNode(int x) : val(x), next(NULL) {} };*/ class TreeLevel { public: ListNode* getTreeLevel(TreeNode* root, int dep) { ListNode *p=new ListNode(-1); ListNode *p1=p; get1(root,p,dep); return p1->next; } void get1(TreeNode* root,ListNode* &list,int dep){ if(dep<=0||root==NULL) return; if(dep==1){ ListNode *he=new ListNode(root->val); list->next=he; list=he; return ; } get1(root->left,list,dep-1); get1(root->right,list,dep-1); } };