1. 程式人生 > >二叉查找樹中由前序轉化為後序

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

二叉查找樹 while urn ++ bsp code color pos 後序

 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 }

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