二叉查找樹中由前序轉化爲後序

 

 

 1 void getPostFromPre(int preL, int preR) {
 2     if (preL > preR) return;
 3     int i = preL + 1, j = preR;
 4     while (i <= preR && pre[i] < pre[preL]) i++;
 5     while (j > preL&&pre[j] >= pre[preL]) j--;
 6 
 7     if (i - j != 1) return;
 8     getPostFromPre(preL + 1, j);
 9     getPostFromPre(i, preR);
10     post.push_back(pre[preL]);
11 }
相關文章
相關標籤/搜索