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 C A

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
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
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
steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY