Returns all values in this entry tree together with their keys. * The order of outputs would be similar to level order traversal, * i.e., first you would get all values together with their keys in * first level from left to right, then second level, and so on. * If tree has no values then it would return {@code null}. * For the example image given in description, the * returned String[][] would look as follows: * * {{"IA","Grow"}, {"ISU","CS228"}} * * NOTE: In this method you are allowed to use * {@link java.util.LinkedList}. * * */
public String[][] getAll() {
// TODO
return null;
}
package edu.iastate.cs228.proj4;
/**
*
* @author
*
*
* An entry tree class.
*
*
*/
public class EntryTree
{
// Dummy root node.
// Made public for grading.
public Node root;
/**
*
* You are allowed to add at most TWO more data fields to
* EntryTree class of int type ONLY if you need to.
*
*/
// All made public for grading.
public class Node implements EntryNode
{
public Node child; // reference to the first child node
public Node parent; // reference to the parent node
public Node prev; // reference to the previous sibling
public Node next; // reference to the next sibling
public K key; // the key for this node
public V value; // the value at this node
public Node(K aKey, V aValue)
{
key = aKey;
value = aValue;
child = null;
parent = null;
prev = null;
next = null;
}
@Override
public EntryNode parent()
{
// TODO
return null;
}
@Override
public EntryNode child()
package edu.iastate.cs228.proj4;
/**
*
* @author
*
*
* An entry tree class.
*
*
*/
public class EntryTree
{
// Dummy root node.
// Made public for grading.
public Node root;
/**
*
* You are allowed to add at most TWO more data fields to
* EntryTree class of int type ONLY if you need to.
*
*/
// All made public for grading.
public class Node implements EntryNode
{
public Node child; // reference to the first child node
public Node parent; // reference to the parent node
public Node prev; // reference to the previous sibling
public Node next; // reference to the next sibling
public K key; // the key for this node
public V value; // the value at this node
public Node(K aKey, V aValue)
{
key = aKey;
value = aValue;
child = null;
parent = null;
prev = null;
next = null;
}
@Override
public EntryNode parent()
{
// TODO
return null;
}
@Override
public EntryNode child()
{
// TODO
return null;
}
@Override
public EntryNode next()
{
// TODO
return null;
}
@Override
public EntryNode prev()
{
// TODO
return null;
}
@Override
public K key()
{
// TODO
return null;
}
@Override
public V value()
{
// TODO
return null;
}
}
public EntryTree()
{
root = new Node(null, null);
}
/**
* Returns the value of the entry with a specified key sequence,
* or {@code null} if this tree contains no entry with this key
* sequence.
*
* This method returns {@code null} if {@code keyarr} is null or
* if its length is {@code 0}. If any element of {@code keyarr}
* is {@code null}, then the method throws a
* {@code NullPointerException}. The method returns the value of
* the entry with the key sequence in {@code keyarr} or {@code null}
* if this tree contains no entry with this key sequence. An example
* is given in provided sample input and output files to illustrate
* this method.
*
* @param keyarr Read description.
* @return Read description.
* @throws NullPointerException Read description.
*/
public V search(K[] keyarr)
{
// TODO
return null;
}
/**
*
* This method returns an array of type {@code K[]} with the longest
* prefix of the key sequence specified in {@code keyarr} such that
* the keys in the prefix label the nodes on the path from the root
* to a node. The length of the returned array is the length of the
* longest prefix.
*
* This method returns {@code null} if {@code keyarr} is {@code null},
* or if its length is {@code 0}. If any element of {@code keyarr} is
* {@code null}, then the method throws a {@code NullPointerException}.
* A prefix of the array {@code keyarr} is a key sequence in the
subarray
* of {@code keyarr} from index {@code 0} to any index {@code m>=0},
* i.e., greater than or equal to; the corresponding suffix is a key
* sequence in the subarray of {@code keyarr} from index {@code m+1} to
* index {@code keyarr.length-1}. The method returns an array of type
* {@code K[]} with the longest prefix of the key sequence specified in
* {@code keyarr} such that the keys in the prefix are, respectively,
* with the nodes on the path from the root to a node. The lngth of the
* returned array is the length of the longest prefix. Note that if the
* length of the longest prefix is {@code 0}, then the method returns
* {@code null}. This method can be used to select a shorted key
sequence
* for an {@code add} command to create a shorter path of nodes in the
* tree. An example is given in the attachment to illustrate how this
* method is used with the {@code #add(K[] keyarr, V aValue)} method.
*
* NOTE: In this method you are allowed to use
* {@link java.util.Arrays}'s {@code copyOf} method only.
*
* @param keyarr Read description.
* @return Read description.
* @throws NullPointerException Read description.
*/
public K[] prefix(K[] keyarr)
{
// TODO
return null;
}
/**
*
* This method returns {@code false} if {@code keyarr} is {@code null},
* its length is {@code 0}, or {@code aValue} is {@code null}. If any
* element of {@code keyarr} is {@code null}, then the method throws a
* {@code NullPointerException}.
*
* This method locates the node {@code P} corresponding to the longest
* prefix of the key sequence specified in {@code keyarr} such that the
* keys in the prefix label the nodes on the path from the root to the
node.
* If the length of the prefix is equal to the length of {@code keyarr},
* then the method places {@code aValue} at the node {@code P} (in place
of
* its old value) and returns {@code true}. Otherwise, the method
creates a
* new path of nodes (starting at a node {@code S}) labelled by the
* corresponding suffix for the prefix, connects the prefix path and
suffix
* path together by making the node {@code S} a child of the node {@code
P},
* and returns {@code true}. An example input and output files
illustrate
* this method's operation.
*
* NOTE: In this method you are allowed to use
* {@link java.util.Arrays}'s {@code copyOf} method only.
*
* @param keyarr Read description.
* @param Read description.
* @return Read description.
* @throws NullPointerException Read description.
*/
public boolean add(K[] keyarr, V aValue)
{
// TODO
return false;
}
/**
* Removes the entry for a key sequence from this tree and returns its
value
* if it is present. Otherwise, it makes no change to the tree and
returns
* {@code null}.
*
* This method returns {@code null} if {@code keyarr} is {@code null} or
its
* length is {@code 0}. If any element of {@code keyarr} is {@code
null}, then
* the method throws a {@code NullPointerException}. The method returns
* {@code null} if the tree contains no entry with the key sequence
specified
* in {@code keyarr}. Otherwise, the method finds the path with the key
sequence,
* saves the value field of the node at the end of the path, sets the
value field
* to {@code null}.
*
* The following rules are used to decide whether the current node and
higher
* nodes on the path need to be removed. The root cannot be removed. Any
node
* whose value is not {@code null} cannot be removed. Consider a non-
root node
* whose value is {@code null}. If the node is a leaf node (has no
children),
* then the node is removed. Otherwise, if the node is the parent of a
single
* child and the child node is removed, then the node is removed.
Finally, the
* method returns the saved old value.
*
*
* @param keyarr Read description.
* @return Read description.
* @throws NullPointerException Read description.
*
*/
public V remove(K[] keyarr)
{
// TODO
return null;
}
/**
*
* This method prints the tree on the console in the output format
* shown in provided sample output file. If the tree has no entry,
* then the method just prints out the line for the dummy root node.
*
*/
public void showTree()
{
// TODO
return;
}
/**
*
* Returns all values in this entry tree together with their keys.
* The order of outputs would be similar to level order traversal,
* i.e., first you would get all values together with their keys in
* first level from left to right, then second level, and so on.
* If tree has no values then it would return {@code null}.
*
* For the example image given in description, the
* returned String[][] would look as follows:
*
* {{"IA","Grow"}, {"ISU","CS228"}}
*
* NOTE: In this method you are allowed to use
* {@link java.util.LinkedList}.
*
*
*/
public String[][] getAll()
{
// TODO
return null;
}
}
Returns all values in this entry tree together with their keys. * The order of outputs...
package hw3; import java.util.LinkedList; /* *********************************************************************** * A simple BST with int keys and no values * * Complete each function below. * Write each function as a separate recursive definition (do not use more than one helper per function). * Depth of root==0. * Height of leaf==0. * Size of empty tree==0. * Height of empty tree=-1. * * TODO: complete the functions in this file. * DO NOT change the Node class. * DO NOT change the name...
You should now be able to edit the IntTree class. Implement each of the functions labeled with You are not allowed to use any kind of loop in your solutions. You may not modify the Node class in any way You may not modify the function headers of any of the functions already present in the file. You may not add any fields to the IntTree class. You may not change or remove the line that reads “package hw2;”...
Would appreciate the answer in the Java coding language please
and thank you!
10d 10h left Java 7 1. Check the Structure Autocomplete Ready 1 > import java.io.*;... 10 ALL A binary tree uses a multi-node data structure where each node may have 0 to 2 child nodes, and has one stored value, its node number in this case. A tree may either be: 11 class Result { * Complete the 'isValid' function below. • An empty tree, the root...
In Java. How would this method look?
LinkedBinaryTree.java
import java.util.Iterator;
public class LinkedBinaryTree implements BinaryTreeADT {
private BinaryTreeNode root;
/**
* Creates an empty binary tree.
*/
public LinkedBinaryTree() {
root = null;
}
/**
* Creates a binary tree from an existing root.
*/
public LinkedBinaryTree(BinaryTreeNode root) {
this.root = root;
}
/**
* Creates a binary tree with the specified element...
PLEASE HELP! The assignment details are in the *noted part of the code. I REALLY need help. import java.util.LinkedList; public class TwoDTree { private TwoDTreeNode root; private int size; public TwoDTree() { clear(); } /** * Returns true if a point is already in the tree. * Returns false otherwise. * * The traversal remains the same. Start at the root, if the tree * is not empty, and compare the x-coordinates of the point passed * in and...
These are all different questions, please answer them separately and label each question Write a static method named conflicts that takes two Maps using Strings as keys and Integers as values. The method should return a Set of Strings. The Set returned by conflicts should be a list of all of the keys that are in conflict between the two Maps. A conflict occurs when two keys point to a different value in the two different maps. (For example, map1...
1) Extend the Binary Search Tree ADT to include
a public method leafCount that returns the number of leaf nodes in
the tree.
2) Extend the Binary Search Tree ADT to include a
public method singleParent-Count that returns the number of nodes
in the tree that have only one child.
3) The Binary search tree ADT is extended to
include a boolean method similarTrees that receives references to
two binary trees and determines whether the shapes of the trees are...
Customer (CustomerId, CustomerName) Employee (EmployeeId, EmployeeName, Salary, SupervisorId) Product(ProductId, ProductName, ListPrice) Orders (OrderId, OrderDate, CustomerId, EmployeeId, Total) OrderedProduct (OrderId, ProductId, Quantity, Price) Write the code to complete the methods in OrderJDBC.java (look for TODO items). <---**IN BOLD** throughout code. /* OrderJDBC.java - A JDBC program for accessing and updating an order database on MySQL. */ import java.io.File; import java.math.BigDecimal; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.ResultSetMetaData; import java.sql.SQLException; import java.sql.Statement; import java.util.Scanner; /** * An application for...
Hi,
So I have a finished class for the most part aside of the toFile
method that takes a file absolute path +file name and writes to
that file. I'd like to write everything that is in my run method
also the toFile method. (They are the last two methods in the
class). When I write to the file this is what I get.
Instead of the desired
That I get to my counsel. I am
having trouble writing my...
Preliminaries Download the template class and the driver file. Objective Learn how to traverse a binary search tree in order. Description For the template class BinarySearchTree, fill in the following methods: insert - Inserts values greater than the parent to the right, and values lesser than the parent to the left.parameters elem - The new element to be inserted into the tree. printInOrder - Prints the values stored in the tree in ascending order. Hint: Use a recursive method to...