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

推荐订阅源

人人都是产品经理
人人都是产品经理
MyScale Blog
MyScale Blog
Y
Y Combinator Blog
罗磊的独立博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
P
Proofpoint News Feed
Google DeepMind News
Google DeepMind News
V
Vulnerabilities – Threatpost
T
The Blog of Author Tim Ferriss
云风的 BLOG
云风的 BLOG
Recorded Future
Recorded Future
N
News and Events Feed by Topic
B
Blog RSS Feed
阮一峰的网络日志
阮一峰的网络日志
博客园_首页
C
CXSECURITY Database RSS Feed - CXSecurity.com
博客园 - 【当耐特】
N
Netflix TechBlog - Medium
博客园 - 叶小钗
B
Blog
Vercel News
Vercel News
T
Tenable Blog
T
The Exploit Database - CXSecurity.com
Spread Privacy
Spread Privacy
T
Threat Research - Cisco Blogs
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Last Week in AI
Last Week in AI
F
Fortinet All Blogs
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Microsoft Security Blog
Microsoft Security Blog
S
Securelist
Microsoft Azure Blog
Microsoft Azure Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
P
Palo Alto Networks Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
D
DataBreaches.Net
Cyberwarzone
Cyberwarzone
Engineering at Meta
Engineering at Meta
Martin Fowler
Martin Fowler
G
GRAHAM CLULEY
Project Zero
Project Zero
Cisco Talos Blog
Cisco Talos Blog
A
Arctic Wolf
C
CERT Recently Published Vulnerability Notes
L
LangChain Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
C
Check Point Blog
A
About on SuperTechFans
W
WeLiveSecurity
The GitHub Blog
The GitHub Blog

博客园 - 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