Code Monkey home page Code Monkey logo

dsa-code-snippet's Introduction

Hey, I'm Aryan Goyal

  • [] I'm a Computer Science student.
  • šŸŒ± Iā€™m currently learning ML, DSA
  • šŸ‘€ Iā€™m looking to collaborate on Open Source Projects.
  • šŸ’¬ Ask me any tech related stuff.
  • āš” Fun fact: I fond of playing Football.

Connect with me:

Vaibhav Goel Ā Ā  Vaibhav Goel Ā Ā 



iaryangoyal

iaryangoyal


dsa-code-snippet's People

Contributors

agnesebesk avatar alcatrazfp avatar anuva04 avatar ardent10 avatar drish-xd avatar hariprasad19036 avatar harshit1123 avatar iaryangoyal avatar letswinoff avatar maheshwar01 avatar manas0522 avatar mrlakshay avatar noeltom787 avatar oliviacarino avatar poojasingh5 avatar pranith45 avatar ritesh-10 avatar sagunjaiswal avatar sgaurav37533 avatar shaleen-23 avatar shashwat010 avatar shresth12-jain avatar siddhants1504 avatar underscoremissa avatar varshaacodes avatar yoqwerty avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

dsa-code-snippet's Issues

Inorder Tree Traversal without Recursion

class Node:

# Constructor to create a new node
def __init__(self, data):
    self.data = data
    self.left = None
    self.right = None

Iterative function for inorder tree traversal

def inOrder(root):

# Set current to root of binary tree
current = root
stack = [] # initialize stack
done = 0
 
while True:
     
    # Reach the left most Node of the current Node
    if current is not None:
         
        # Place pointer to a tree node on the stack
        # before traversing the node's left subtree
        stack.append(current)
     
        current = current.left

     
    # BackTrack from the empty subtree and visit the Node
    # at the top of the stack; however, if the stack is
    # empty you are done
    elif(stack):
        current = stack.pop()
        print(current.data, end=" ") # Python 3 printing
     
        # We have visited the node and its left
        # subtree. Now, it's right subtree's turn
        current = current.right

    else:
        break
  
print()

Driver program to test above function

""" Constructed binary tree is
1
/
2 3
/
4 5 """

root = Node(1)
root.left = Node(2)
root.right = Node(3)
root.left.left = Node(4)
root.left.right = Node(5)

inOrder(root)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    šŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. šŸ“ŠšŸ“ˆšŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ā¤ļø Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.