Create a python program with the same output as the given image below - which accepts a one-liner input just like the image below. I have started my code already but it only takes numbers, and the input is not a one-liner. You can use my code as a reference or create another one. Thanks.

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:

Create a python program with the same output as the given image below - which accepts a one-liner input just like the image below. I have started my code already but it only takes numbers, and the input is not a one-liner. You can use my code as a reference or create another one. Thanks.

 

# Main program
inorder_list = []
preorder_list = []
postorder_list = []
n = int(input("How many nodes want to enter? "))

# Methods
def search(arr, x, n):
     for i in range(n):
          if (arr[i] == x):
               return i

     return -1


def PostOrderT(Ino, preo, n):
     root = search(Ino, preo[0], n)
     if (root != 0):
          PostOrderT(Ino, preo[1:n], root)
     if (root != n - 1):
          PostOrderT(Ino[root + 1: n],
                         preo[root + 1: n],
                         n - root - 1)
     print(preo[0], end=" ")


# Make new node
class newNode:
     def __init__(self, data):
          self.data = data
          self.left = self.right = None


# Construct binary tree
def MakeTree(Ino, posto, inoStrt, inoEnd, p_Index):
     if (inoStrt > inoEnd):
          return None
     node = newNode(posto[p_Index[0]])
     p_Index[0] -= 1

     if (inoStrt == inoEnd):
          return node
     iIndex = search(Ino, inoStrt, inoEnd, node.data)
     node.right = MakeTree(Ino, posto, iIndex + 1,
                         inoEnd, p_Index)
     node.left = MakeTree(Ino, posto, inoStrt,
                         iIndex - 1, p_Index)

     return node


def bTree(Ino, posto, n):
     p_Index = [n - 1]
     return MakeTree(Ino, posto, 0, n - 1, p_Index)


def search(arr, astrt, aend, value):
     i = 0
     for i in range(astrt, aend + 1):
          if (arr[i] == value):
               break
     return i


def PreOrderT(node):
     if node == None:
          return
     print(node.data, end=" ")
     PreOrderT(node.left)
     PreOrderT(node.right)

print("Enter INORDER:")
for i in range(0, n):
     ele = int(input())

     inorder_list.append(ele) # adding the element

print(inorder_list)

print("\nWould you like to use Preorder or Postorder?")
choice = int(input("Press [1] for PREORDER and Press [2] for POSTORDER>> "))
if choice == 1:
     print("Enter PREORDER: ")
     for i in range(0, n):
          ele = int(input())
          preorder_list.append(ele) # adding the element
     print(preorder_list)
     print("\nMissing Traversal Identified!")
     print("POSTORDER traversal: ")
     bTree(inorder_list, preorder_list, n)
elif choice == 2:
     print("Enter POSTORDER: ")
     for i in range(0, n):
          ele = int(input())
          postorder_list.append(ele) # adding the element
     print(postorder_list)
     print("\nMissing Traversal Identified!")
     print("PREORDER traversal: ")
     PostOrderT(inorder_list, preorder_list, n)
else:
     print("Invalid choice")

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 3 steps with 1 images

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