由买买提看人间百态

topics

全部话题 - 话题: ptail
(共0页)
n****t
发帖数: 241
1
来自主题: JobHunting版 - Google校园面试题
我看到貌似正确的一个解法,加了很多限制条件。。。
面试题之二叉搜索树的中位数 收藏
这个问题不算是很常见的问题,基本上在中文的论坛社区没有看到过,遇见这个是因为
偶尔在http://www.ocf.berkeley.edu/~wwu/cgi-bin/yabb/YaBB.cgi 上面注册了账号而看到的,题目如下:
Given a BST (Binary search Tree) how will you find median in that?
Constraints:
* No extra memory.
* Function should be reentrant (No static, global variables allowed.)
* Median for even no of nodes will be the average of 2 middle elements and
for odd no of terms will be middle element only.
* Algorithm should be efficient in terms of comple... 阅读全帖
w******g
发帖数: 189
2
来自主题: JobHunting版 - L 家面试高频题, 怎么解
贴一个以作参考:
DLNode * flatten_list(DLNode *head)
{
DLNode *p, *phead, *ptail;
p = head;
while(p->next){
p = p->next;
}
phead = head;
ptail = p;
while(phead->next != NULL){
if(phead->child != NULL){
ptail->next = phead->child;
phead->child->prev = ptail;
while(ptail->next != NULL){
ptail = ptail->next;
}
}
phead = phead->next;
}
return head;
}
(共0页)