Showing posts with label Pre Order Traversal. Show all posts
Showing posts with label Pre Order Traversal. Show all posts

Inorder and Preorder traversals of a Binary Tree given output the Postorder traversal of it.

Inorder and Preorder traversals of a Binary Tree given output the Postorder traversal of it.

Input:
In-order traversal in[] = {4, 2, 5, 1, 3, 6}
Pre-order traversal pre[] = {1, 2, 4, 5, 3, 6}

Output:
Post-order traversal is {4, 5, 2, 6, 3, 1}

Binary Tree in Java

Implementation of Binary Tree in Java Language.


import java.io.*;
import java.util.*; 

class Node
   {
   public int iData;              // data item (key)
   public double dData;           // data item