数据结构练习(05)二元查找树的后序遍历结果
http://zhedahht.blog.163.com/blog/static/25411174200725319627/
#include <cstdio> #include <cstdlib> #include <cstring> bool verify_bft_squence(int a[], int s, int e) { if (a == NULL || s > e) return false; if (s == e) return true; int i; for (i = s; i <= e; ++i) if (a[i] > a[e]) break; int j; for (j = i; j <= e; ++j) if (a[j] < a[e]) return false; bool left = true; if (s <= i-1) left = verify_bft_squence(a, s, i-1); bool right = true; if (i <= e - 1) right = verify_bft_squence(a, i, e - 1); return (left && right); } int main() { int a[10] = {0, 5, 7, 6, 9, 11, 10, 8}; bool flag = verify_bft_squence(a, 1, 7); return 0; }
-------------------------------------------------------
kedebug
Department of Computer Science and Engineering,
Shanghai Jiao Tong University
E-mail: kedebug0@gmail.com
GitHub: http://github.com/kedebug
-------------------------------------------------------
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步