Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need help with making an in order iterator using a parent pointer in Java. The class outline is below. public class BinaryTree { //Implements a

Need help with making an in order iterator using a parent pointer in Java. The class outline is below.

public class BinaryTree { //Implements a Binary Tree of Strings private class Node { private Node left; private String data; private Node right; private Node _parent_; //reference to the parent node // the parent is null for the root node private Node(Node L, String d, Node r, Node p) { left = L; data = d; right = r; parent = p; } } private Node root;

public BinaryTree() { //create an empty tree root = null; }

public BinaryTree(String d) { //create a tree with a single node root = new Node(null,d,null,null); }

public class InorderIterator implements Iterator { //An iterator that returns data in the tree in an in order pattern //the implementation must use the parent pointer and must not use an //additional data structure

public InorderIterator() { } public boolean hasNext() { return true; } public String next() { } }

public Iterator _inorder_() {

//return a new in order iterator object } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Graph Databases

Authors: Ian Robinson, Jim Webber, Emil Eifrem

1st Edition

1449356265, 978-1449356262

More Books

Students also viewed these Databases questions