1,暴力解法:直接找到根节点,然后开始中序排列,将结果储存在队列中,再取出
时间复杂度:O(n)
空间复杂度:O(n)
public class Solution { reeLinkNode root; TreeLinkNode Node; Queuequeue = new LinkedList(); public TreeLinkNode GetNext(TreeLinkNode pNode){ if(pNode == null) return null; root = pNode; while(root.next != null){ root = root.next; } Queue queue = get(root); while(true){ Node = queue.poll(); if( Node == pNode) break; } return queue.poll(); } public Queue get(TreeLinkNode root){ if(root == null) return null; get(root.left); queue.offer(root); get(root.right); return queue; } }