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

import java.util.*;

public class BST
{
    // instance variables
    private BSTNode m_root;
    private int m_size;
   
    // constructor
    public BST()
    {
        m_root = null;
        m_size = 0;
    }
   
    // This method returns the number of elements in the tree.
    // Do not make any changes to this method!
    public int size()
    {
        return m_size;
    }
   
    // This method clears the content of the tree.
    // Do not make any changes to this method!
    public void clear()
    {
        m_root = null;
        m_size = 0;
    }   
   
    // This non-recursive method takes a string and inserts it into the binary
    // search tree, keeping the tree ordered.
    public void add(String value)
    {
        // TODO: implement this method using a non-recursive solution
    }
   
    // This non-recursive method returns a string that represents the in-order traversal
    // of the binary search tree.
    public String inOrder()
    {  
        // TODO: implement this method using a non-recursive solution
       
        return ""; // replace this statement with your own return
    }
   
    // This method returns the largest element in the binary search tree. You
    // are not allowed to create any additional structures, including but not
    // limited to arrays, stacks, queues, or other trees.
    public String max()
    {
        // TODO: implement this method
       
        return ""; // replace this statement with your own return
    }
   
    // This method takes a reference to the root of the expression, evaluates
    // the tree, and returns the result as an int.
    public int evaluate(BSTNode node)
    {
        // TODO: implement this method
       
        return -1; // replace this statement with your own return
    }
}

 

public class BSTNode
{
// data members
private String m_value;
private BSTNode m_left;
private BSTNode m_right;
// constuctor
public BSTNode(String value)
{
m_value =
value;
m_left = null;
m_right
}
null;
// member methods
public String getInfo()
{
return m_value;
}
public BSTNode getLeft()
{
return m_left;
}
public BSTNode getRight()
{
return m_right;
}
public void setLeft(BSTNode left)
{
m_left
}
left;
%D
public void setRight(BSTNode right)
{
m_right
}
}
right;
Transcribed Image Text:public class BSTNode { // data members private String m_value; private BSTNode m_left; private BSTNode m_right; // constuctor public BSTNode(String value) { m_value = value; m_left = null; m_right } null; // member methods public String getInfo() { return m_value; } public BSTNode getLeft() { return m_left; } public BSTNode getRight() { return m_right; } public void setLeft(BSTNode left) { m_left } left; %D public void setRight(BSTNode right) { m_right } } right;
a. Completing the BST class
You are provided with the files "BSTNode.java" and "BST.java". You are required to
complete the methods in the latter file to implement a binary search tree. This tree is designed
to store only strings and it does not allow duplicate elements. You need to write the following
three methods:
add (String v) – This non-recursive method takes a String and inserts it into the binary
search tree, keeping the tree ordered (You can use the compareTo method to make
comparisons). It does not allow inserting the same element for more than once.
inOrder ()
This non-recursive method builds and returns a string that represents the in-
order traversal of the binary search tree.
max () – This method returns the largest element in the binary search tree. You are not allowed
to create any additional structures, including but not limited to arrays, stacks, queues, or
other trees.
evaluate () – When provided with an expression tree, this method evaluates
the expression represented by the tree and returns the result. For
example, it will return 108 if the root of the tree on the right is passed into
the method. This is because (15 + 21) * 3 = 108.
+
3
15
21
Transcribed Image Text:a. Completing the BST class You are provided with the files "BSTNode.java" and "BST.java". You are required to complete the methods in the latter file to implement a binary search tree. This tree is designed to store only strings and it does not allow duplicate elements. You need to write the following three methods: add (String v) – This non-recursive method takes a String and inserts it into the binary search tree, keeping the tree ordered (You can use the compareTo method to make comparisons). It does not allow inserting the same element for more than once. inOrder () This non-recursive method builds and returns a string that represents the in- order traversal of the binary search tree. max () – This method returns the largest element in the binary search tree. You are not allowed to create any additional structures, including but not limited to arrays, stacks, queues, or other trees. evaluate () – When provided with an expression tree, this method evaluates the expression represented by the tree and returns the result. For example, it will return 108 if the root of the tree on the right is passed into the method. This is because (15 + 21) * 3 = 108. + 3 15 21
Expert Solution
trending now

Trending now

This is a popular 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