Redian新闻
>
紧急求助:把iphone通讯录删了,忘记备份怎么办?
avatar
紧急求助:把iphone通讯录删了,忘记备份怎么办?# Apple - 家有苹果
H*M
1
u are given a binary search tree,
each node has a parent, left and right
do pre-order/in-order traversal without stack.
cannot change the structure of Node.
test cases: 8 6 7 5 4 9 10 11 12
test your codes using the test case above.
avatar
l*n
2
升级到4s之后,原来的iphone 3g还没来得及同步通讯录,就被我一时手贱删了。(主要原因是那个3g的一直找不到wifi,
我按照网上的操作修复,结果想也没想,就erase all content了,因为那个手机上之前的app和其他东西除了通讯录都被我
转移了,所以脑子没想事)以前的备份的电脑坏了,之后一直没有备份。。。。现在这个情况的话,通讯录还找得回吗?
另外sim卡里不知道有没有存,不过因为新卡激活,旧卡作废,貌似也没法弄。。。
apple care早过期,不知道找苹果店有木有办法呢?
谢谢各位了。
avatar
t*r
3
does using recursion = using stack?

【在 H*M 的大作中提到】
: u are given a binary search tree,
: each node has a parent, left and right
: do pre-order/in-order traversal without stack.
: cannot change the structure of Node.
: test cases: 8 6 7 5 4 9 10 11 12
: test your codes using the test case above.

avatar
z*e
4
你以前旧手机和iTunes同步时有没有同步联系人,有的话再同步到新手机就好了。
avatar
z*e
5
of course.
theoritically, the stack is used to save parent, since there is pointer to
parent, no need to use stack/recursion. but coding might take a while...

【在 t**r 的大作中提到】
: does using recursion = using stack?
avatar
l*n
6
呜呜,就是因为没有。呵呵,还是谢谢你了!

【在 z****e 的大作中提到】
: 你以前旧手机和iTunes同步时有没有同步联系人,有的话再同步到新手机就好了。
avatar
h*e
7
what about building a finite state machine with 3 states? keep a pointer to the current node, and a state.
we can enter a node in three ways:
A. from parent,
B. from left child, and
C. from right child.
case A: go left, keep state A (if no left child, keep current, state=B)
case B: go right, state=A (if no right child, keep current, state=C)
case C: go up, change state to B or C
initial state is A, initial pointer is root.
avatar
H*M
8
ft.可以recursion还往这发吗

【在 t**r 的大作中提到】
: does using recursion = using stack?
avatar
k*e
9
geniusxsy has a post on this problem. you can search for it.

【在 H*M 的大作中提到】
: ft.可以recursion还往这发吗
avatar
H*M
10
我看到过那个,可是是有问题的,not working.

【在 k***e 的大作中提到】
: geniusxsy has a post on this problem. you can search for it.
avatar
g*y
11
I remembered I posted a solution with stack.
If parent links are allowed, it's actually easier, but similar to the stack version.
in_order:
void go_to_leftmost(Node *&root){
while(root->left){ root = root->left;}
}
void in_order(Node *root){
go_to_leftmost(root);
while(root){
print(root);
if(root->right){ root = root->right; go_to_leftmost(root);}
else{
while(root->parent && root==root->parent->right) root = root->parent;
root = root->parent;
}
}
}
post_order:
void go_to_leftrightmost(Node *&roo

【在 H*M 的大作中提到】
: 我看到过那个,可是是有问题的,not working.
avatar
H*M
12
这个不对吧,
你看这个BST:
insert order: 8 6 5 4 7 9 10 11 12
这个会stuck在右边9-10-11-12那块
你编译code就知道了. 用上面这个做test case
只有post order比较好写,in和pre的比较不好写

stack version.

【在 g*******y 的大作中提到】
: I remembered I posted a solution with stack.
: If parent links are allowed, it's actually easier, but similar to the stack version.
: in_order:
: void go_to_leftmost(Node *&root){
: while(root->left){ root = root->left;}
: }
: void in_order(Node *root){
: go_to_leftmost(root);
: while(root){
: print(root);

avatar
k*e
13
i did it with the same method. it works.
but i really did not like reading others' code :) I will write some analysis.
suppose we are doing inorder
i think the key point is:
when x is visited, we should know where to go next.
1. x has right kid, then sure go right.
2. x did not have right kid, then we need to go to an ancester of x, say y,
that has path to x as LRRR...R
3. if y cannot be found, done!
4. y exists. then visit y and start from y as above again.

stack version.

【在 g*******y 的大作中提到】
: I remembered I posted a solution with stack.
: If parent links are allowed, it's actually easier, but similar to the stack version.
: in_order:
: void go_to_leftmost(Node *&root){
: while(root->left){ root = root->left;}
: }
: void in_order(Node *root){
: go_to_leftmost(root);
: while(root){
: print(root);

avatar
g*y
14
are you talking about in order or post order?
for in order traversal, after it prints 9, since 9 has a right child 10, and
run go_to_leftmost() on 10 has virtually no effect, so next one to print is
10, and then 11, 12
after printing 12, in the part:
else{
while(...)...
...
}
root will become null, therefore end the traversal.
pre-order is a little more complicated, I agree, but in-order and post-order may be not that difficult.
I'm trying to write puseudo code for the pre-order traversal withou

【在 H*M 的大作中提到】
: 这个不对吧,
: 你看这个BST:
: insert order: 8 6 5 4 7 9 10 11 12
: 这个会stuck在右边9-10-11-12那块
: 你编译code就知道了. 用上面这个做test case
: 只有post order比较好写,in和pre的比较不好写
:
: stack version.

avatar
H*M
15
是对的。my bad...

and
is

【在 g*******y 的大作中提到】
: are you talking about in order or post order?
: for in order traversal, after it prints 9, since 9 has a right child 10, and
: run go_to_leftmost() on 10 has virtually no effect, so next one to print is
: 10, and then 11, 12
: after printing 12, in the part:
: else{
: while(...)...
: ...
: }
: root will become null, therefore end the traversal.

avatar
x*r
16
What about this one for preorder?
void preorder(node *root)
{
if(!root)
return;
node *current;
node *end;
for(end=root;end->right!=NULL;end=end->right);
current=root;
while(1)
{
visit(current);
if(current==end) return;
if(current->left)
current=current->left;
else if(current->right)
current=current->right;
else
{
for(;current==current->parent->right||!current->parent->right;
cu
avatar
g*y
17
有个问题了,
你的end没找对
应该这样:
end = root;
while(end has at least one child){
if(end->right){
end = end->right;
}else{
end = end->left;
}
}
不过算法貌似还是对的

【在 x******r 的大作中提到】
: What about this one for preorder?
: void preorder(node *root)
: {
: if(!root)
: return;
: node *current;
: node *end;
: for(end=root;end->right!=NULL;end=end->right);
: current=root;
: while(1)

avatar
x*r
18
Thank you very much.
My fault.
What about the rest?

【在 g*******y 的大作中提到】
: 有个问题了,
: 你的end没找对
: 应该这样:
: end = root;
: while(end has at least one child){
: if(end->right){
: end = end->right;
: }else{
: end = end->left;
: }

avatar
r*l
19
Ithink just need to add one more condition
current->Parent != NULL in for loop to ensure current->Parent is valid, so
you can visit current->Parent->right.

【在 x******r 的大作中提到】
: Thank you very much.
: My fault.
: What about the rest?

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。