Computer Networking: A Top-Down Approach (7th Edition)
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN: 9780133594140
Author: James Kurose, Keith Ross
Publisher: PEARSON
Bartleby Related Questions Icon

Related questions

Question

PYTHON:

Can you please help me to modify this code in a way that it prints out the same output as the image below.

 

class Node:

def __init__(self, key):
self.left = None

self.right = None

self.val = key


# this is the function for Inorder

def printInorder(root):
if root:
# here calling the left child

printInorder(root.left)

# here printing the node data

print(root.val, end=" "),

# here calling the right child

printInorder(root.right)


# this is the Preorder method

def printPreorder(root):
if root:
# here printing the node data

print(root.val, end=" "),

# here calling the left child

printPreorder(root.left)

# here calling the right child

printPreorder(root.right)


# thsi is the postorder method

def printPostorder(root):
if root:
# here calling the left child

printPostorder(root.left)

# here calling the right child

printPostorder(root.right)

# here printing the node data

print(root.val, end=" "),

# this is the main function


if __name__ == "__main__":
root = Node('G')

root.left = Node('D')

root.right = Node('B')

root.left.left = Node('E')

root.left.right = Node('A')

root.right.left = Node('C')

root.right.right = Node('F')

# here calling the inorder method

print("Inorder:")

printInorder(root)

print('')

# here calling the Preorder method

print("Preorder:")

printPreorder(root)

print('')

# here calling the Postorder method

print("Postorder:")

printPostorder(root)

Please input your INORDER>> G D BE A C F
Would you like to use PREORDER or POSTORDER?
Press 1 for PREORDER and press 2 for POSTORDER>> 1
Please input your PREORDER>> A B D GEF C
Inorder: G D BE A C F
Preorder: A B D G E F C
Missing Traversal Identified!
Postorder: G D E B F CA
expand button
Transcribed Image Text:Please input your INORDER>> G D BE A C F Would you like to use PREORDER or POSTORDER? Press 1 for PREORDER and press 2 for POSTORDER>> 1 Please input your PREORDER>> A B D GEF C Inorder: G D BE A C F Preorder: A B D G E F C Missing Traversal Identified! Postorder: G D E B F CA
Expert Solution
Check Mark
Knowledge Booster
Background pattern image
Similar questions
Recommended textbooks for you
Text book image
Computer Networking: A Top-Down Approach (7th Edi...
Computer Engineering
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:PEARSON
Text book image
Computer Organization and Design MIPS Edition, Fi...
Computer Engineering
ISBN:9780124077263
Author:David A. Patterson, John L. Hennessy
Publisher:Elsevier Science
Text book image
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:9781337569330
Author:Jill West, Tamara Dean, Jean Andrews
Publisher:Cengage Learning
Text book image
Concepts of Database Management
Computer Engineering
ISBN:9781337093422
Author:Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:Cengage Learning
Text book image
Prelude to Programming
Computer Engineering
ISBN:9780133750423
Author:VENIT, Stewart
Publisher:Pearson Education
Text book image
Sc Business Data Communications and Networking, T...
Computer Engineering
ISBN:9781119368830
Author:FITZGERALD
Publisher:WILEY