Skip to content

zigzag traversal in a binary tree #120

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

Merged
merged 1 commit into from
Nov 7, 2020
Merged

zigzag traversal in a binary tree #120

merged 1 commit into from
Nov 7, 2020

Conversation

SakshiiAgrawal
Copy link
Contributor

@SakshiiAgrawal SakshiiAgrawal commented Oct 21, 2020

The idea is to use two stacks. We can use one stack for printing from left to right and other stack for printing from right to left. In every iteration, we have nodes of one level in one of the stacks. We print the nodes, and push nodes of next level in other stack.

I am creating a pull request for...

  • [yes ] New algorithm
  • Update to an algorithm
  • Fix an error
  • Other - Describe below

The idea is to use two stacks. We can use one stack for printing from left to right and other stack for printing from right to left. In every iteration, we have nodes of one level in one of the stacks. We print the nodes, and push nodes of next level in other stack.
Copy link
Contributor

@hemanth-kotagiri hemanth-kotagiri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

s2.pop()
print(temp.data, end = " ")

# Note that is rightt is appended before left
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one small change. rightt to right. Writing well-documented code is extremely important. Try fixing any other issues of the same kind. Code LGTM.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, will do it

Copy link
Member

@abranhe abranhe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks so much for your contribution to The All ▲lgorithms Project. Without people like you submitting Pull Requests we couldn't run this project. You rock!

@abranhe abranhe merged commit 7f12f2c into AllAlgorithms:master Nov 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants