惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
WordPress大学
WordPress大学
宝玉的分享
宝玉的分享
人人都是产品经理
人人都是产品经理
博客园 - 聂微东
IT之家
IT之家
V
V2EX
Jina AI
Jina AI
V
Visual Studio Blog
有赞技术团队
有赞技术团队
博客园 - 司徒正美
博客园 - 叶小钗
The Cloudflare Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
小众软件
小众软件
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
博客园 - 三生石上(FineUI控件)
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Google DeepMind News
Google DeepMind News
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
腾讯CDC
Google Online Security Blog
Google Online Security Blog
博客园 - 【当耐特】
Apple Machine Learning Research
Apple Machine Learning Research
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
N
News and Events Feed by Topic
N
News and Events Feed by Topic
The Last Watchdog
The Last Watchdog
W
WeLiveSecurity
月光博客
月光博客
Security Archives - TechRepublic
Security Archives - TechRepublic
Webroot Blog
Webroot Blog
SecWiki News
SecWiki News
博客园_首页
罗磊的独立博客
量子位
Latest news
Latest news
I
Intezer
V
Vulnerabilities – Threatpost
A
Arctic Wolf
Last Week in AI
Last Week in AI
Recent Commits to openclaw:main
Recent Commits to openclaw:main
S
SegmentFault 最新的问题
S
Security Affairs
阮一峰的网络日志
阮一峰的网络日志
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
酷 壳 – CoolShell
酷 壳 – CoolShell
P
Palo Alto Networks Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
N
News | PayPal Newsroom

博客园 - Zero Lee

调用栈(call stack) 关于STL allocator Calculate maximum sum of any subarray set Calcuate power n of x recursively 设计包含min函数的栈 类模板的模板友元函数定义 一道百度的面试题解答 非printf形式的十六进制和二进制打印(雅虎面试题) 一道腾讯面试题 (转)C++中extern “C”含义深层探索 selection algorithm to select nth small elements based on partition 删除与某个字符相邻且相同的字符 产生全排列的方法解析 一组数的全排列和组合程序实现 求一个正整数的平方根程序实现 [转]多线程队列的算法优化 [转载] STL allocator的介绍和一个基于malloc/free的allocator的简单实现 如何将一片内存链接成链表 One simple counted object pointer
Convert one binary search tree to double-linked list
Zero Lee · 2012-06-17 · via 博客园 - Zero Lee

Given one binary search tree, and convert it to one double-linked list
Cpp code demo as below:

 1 struct BSTreeNode
 2 {
 3     int m_value;
 4     BSTreeNode* m_pLeft;
 5     BSTreeNode* m_pRight;
 6 };
 7 
 8 BSTreeNode* convert(BSTreeNode* phead, bool asRight)
 9 {
10     if (!phead)
11         return NULL;
12     BSTreeNode* pLeft = 0, *pRight=0;
13     if (phead->m_pLeft)
14         pLeft = convert(phead->m_pLeft, false);
15     if (pLeft) {
16         pLeft->m_pRight = phead;
17         phead->m_pLeft = pLeft;
18     }
19     if (phead->m_pRight)
20         pRight = convert(phead->m_pRight, true);
21     if (pRight) {
22         pRight->m_pLeft = phead;
23         phead->m_pRight = pRight;
24     }
25     BSTreeNode* ptmp = phead;
26     if (asRight) {
27         while (ptmp->m_pLeft) {
28             ptmp = ptmp->m_pLeft;
29         }
30     } else {
31         while (ptmp->m_pRight) {
32             ptmp = ptmp->m_pRight;
33         }
34     }
35     return ptmp;
36 }
37 
38 BSTreeNode* convert2doublelist(BSTreeNode* phead)
39 {
40     return convert(phead, true);
41 }
42