Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

二叉树遍历-速记法 #8

Open
chaojun-zhang opened this issue Feb 2, 2020 · 0 comments
Open

二叉树遍历-速记法 #8

chaojun-zhang opened this issue Feb 2, 2020 · 0 comments

Comments

@chaojun-zhang
Copy link
Owner

chaojun-zhang commented Feb 2, 2020

先序遍历

S;
p= root;
while(p不空 || S不空){
    while(p不空){
        访问p节点;
        p的右子树入S;
        p = p的左子树;
    }
    p = S栈顶弹出;
}

后序遍历

S;
p= root;
while(p不空 || S不空){
    while(p不空){
        访问p节点;
        p的左子树入S;
        p = p的右子树;
    }
    p = S栈顶弹出;
}
结果序列逆序;

中序遍历

S;
p= root;
while(p不空 || S不空){
    while(p不空){
        pS;
        p = p的左子树;
    }
    p = S栈顶弹出;
    访问p;
    p = p的右子树;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant