如果child有到parent的ref的话。
所在版块:求学狮城 发贴时间:2007-09-24 14:50

用户信息
复制本帖HTML代码
高亮: 今天贴 X 昨天贴 X 前天贴 X 
Let
struct treeNode{
int id;
treeNode *left;
treeNode *right;
treeNode *par;
};

DFS(treeNode *root){
treeNode *cur=root;
while (cur!=NULL){
printf("%d, ", cur->id);
if (cur->left!=NULL){
cur=cur->left;
}
else if (cur->right!=NULL)
cur=cur->right;
else{
treeNode *par=cur->par;
while (par!=NULL){
if (par->left==cur && par->right!=NULL){
cur=par->right;
break;
}
cur=par;
par=par->par;
}
if (par==NULL) cur=NULL;
}
}
}

其实就是depth first, 应该是O(3n)=O(n)吧。
.
欢迎来到华新中文网,踊跃发帖是支持我们的最好方法!

 相关帖子 我要回复↙ ↗回到正文
anyone interested to discuss about the last question in ACM this year? <Tunnels chancing   (75 bytes , 1138reads )
这样可以么? 房间   (343 bytes , 430reads )
I have revised the solution. 房间   (737 bytes , 369reads )
似乎还是不行 bugzzj   (221 bytes , 390reads )
是可以的 房间   (1023 bytes , 329reads )
看错了 房间   (154 bytes , 338reads )
And 房间   (88 bytes , 308reads )
顺带询问一个问题 房间   (267 bytes , 498reads )
如果child有到parent的ref的话。 bugzzj   (524 bytes , 450reads )
gr8. 房间   (142 bytes , 332reads )
construct a graph as follows icky   (178 bytes , 368reads )
disagree bugzzj   (149 bytes , 375reads )
so assume the spy enters 2 icky   (91 bytes , 345reads )
i think we can destroy the tunnels 2 0 and 2 1 simultaneously. bugzzj   (0 bytes , 346reads )
ok, i misunderstood the problem icky   (0 bytes , 322reads )
choose one of 3 or 4 icky   (0 bytes , 309reads )
opps! you are right. 吴永铮   (76 bytes , 311reads )
agree 吴永铮   (0 bytes , 272reads )
maxflow from vertex 0 to vertex 1 icky   (0 bytes , 317reads )
min-cut problem? icky   (54 bytes , 388reads )