I don't see any nodes that I add. Not sure why getting this error.
duplicate found
Exception in thread "main" java.lang.NullPointerException
at binarysearchtree.delete(binarysearchtree.java:111)
at binarysearchtree.main(binarysearchtree.java:196)
Java Result: 1
public class node<T>
I'm trying to build a method that can search a binary search tree for a specific target and then return the number of probes it took to get there. It seems to me that the best way to do this would be a recursive search method and a counter that tracks the number of calls. But I'm struggling with how to implement this. Here's the code I have so far. what works/doesn't work with the method.
// Method to search the tree for a specific name and // return the number of probes public T search(BTNode<T> btNode) {
The assignment is meant to understand and practice tree concepts, tree traversals and recursion. I am requested to use the tree to print the expressions by three ways and evaluate the expression in post-order. This is my node class,
package hw10; public class Node { String value; Node left, right; public Node(String value) {
Is there a way that I can save a binary search algorithm to a text file or something, so that it will always contain more information? The reason why I ask this is because I have BST like project which is supposed to act the game Twenty Questions, were it asks a person 20 Q's until it guess the answer. However, although my project does not require you to save stuff to a file, I find it rather very useful and cool if I could do that.So for example it would start out something like this:
Think of an animal and I will guess it. Does it have legs? YES Is it a cat? YES I win! Continue? YES
Think of an animal and I will guess it. Does it have legs? NO Is it a snake? YES I win! Continue? YES
Think of an animal and I will guess it. Does it have legs? NO Is it a snake? NO I give up. What is it? EARTHWORM Please type a question whose answer is yes for an earthworm and no for a snake. DOES IT LIVE UNDERGROUND? Continue? YES
Think of an animal and I will guess it. Does it have legs? NO Does it live underground? NO Is it a snake? NO I give up. What is it? FISH Please type a question whose answer is yes for an earthworm and no for a snake. DOES IT LIVE IN WATER? Continue? NO Good-bye.
However, if the user exits the program then everything will be lost and go to waste. So once again, is there a way that I can save all of these inputs to a file or something and then read it in again?
I am trying to implement a simple binary search tree . How can I make a node in the tree which should store two pieces of information: a String variable called name, and a int variable called mark. ..
public class BinarySearchTree<E> implements Comparable<E> { public BinaryTree<E> root; int size; int mark; String name; // Constructor public BinarySearchTree()
I'm trying to implement a Binary Search Tree that accepts strings. I cannot figure out how to compare the string value in my add method against the node object. While I could make the node class data be the string type I am trying to make the code be as reusable as possible. So my question is this, is there a simple way I can compare the two that I am missing?
public class BTNode<E> { private E data; private BTNode<E> left, right; //constructor public BTNode(E initialData, BTNode<E> initialLeft, BTNode<E> initialRight) { data = initialData; left = initialLeft; right = initialRight;
I am trying to make binary search tree...I am trying to construct the left part of binary search tree with root node set as 70...It is not working ...My code is
public class Node { /** * @param args */
int root; Node left; Node right; public void insertNode(Node node, int num) { //Node nodeRoot = this; //root of tree we have set to 70...constructing only left of tree with root=70
I am trying to draw a binary node tree to a text file.
public class BinaryTreeExample { public static void main(String[] args) { new BinaryTreeExample().run(); } static class Node { Node left; Node right; int value; public Node(int value) {
[Code] .....
This will output:
Building tree with rootvalue25 ================================= Inserted 11 to left of node 25 Inserted 15to right of node 11 Inserted 16to right of node 15 Inserted 23to right of node 16 Inserted 79to right of node 25 Traversing tree in order ================================= Traversed 11 Traversed 15 Traversed 16 Traversed 23 Traversed 25 Traversed 79
I need to print this information in the form of a graphic to a text file. so for example:
The purpose of this function is to use a Movie object and a binary search tree to find all movies that have been read in through a file that have a certain rating (G,PG,PG-13,R). The error I am getting is that it seems I am not traversing fully through the tree and therefore only some movies with the rating I search for are output, not all of them with that rating. I have tried figuring out why this is happening and at first I thought my tree was unbalanced, but I am sure it is simply because I am not traversing the tree correctly. I think my implementation in the main is close to what I need but it needs some tweaking. This is my BST class which I created and required to use for this purpose.
public class BinarySearchTree { /** * The head of the tree. */ private Node root; /** * Constructor that declares the head of tree to null. */ public BinarySearchTree() { root = null; } /** * Returns null if head of tree is empty. * @return null if head of tree is empty. */ public boolean isEmpty(){
So in my binary search tree I'm trying to write a method that deletes the idem but for some reason it's not working. I have two things, I have the method and then another piece of code that tests the deletion method. Here's the actual method
i wrote it on paper with my examples.and just for laughts , i uploaded another picture that dont belong to my problem. its just my way to understand binary search tree implementation , so i wanted so share.just for laught : looks like the map of the universe.
now my problem : why after i changed Current to Current.left, Parent still has the value of root. i draw and wrote it on a paper. to be clear as possible - picture 2 :
I Write a Java program to parse a syntactically correct arithmetical expression and produce an equivalent Expression TREE. Remember, in an expression tree the terminal nodes are variables and constants, and the interior nodes are operators (such as +,-,*,/).
For instance the expression: (1 + 2) * 3 can be represented by the following tree:
But when i Execute the program it Shows only Prefix and postfix .But the requered output is in inorder preorder and postorder so how to solve these error
import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.util.Scanner; import javax.swing.tree.TreeNode; public class InToPost { private static String str;
I'm trying to use LinkedBinarySearchTree but a lot of the variables are protected in BinaryTreeNode. I am creating a BinaryTreeNode object but it still isn't allowing me to use them. The variables I am trying to use are element, left, and right.
import ch11.exceptions.*; import ch10.LinkedBinaryTree; import ch10.BinaryTreeNode; /** * LinkedBinarySearchTree implements the BinarySearchTreeADT interface with links.
*/ public class LinkedBinarySearchTree<T> extends LinkedBinaryTree<T> implements BinarySearchTreeADT<T>
The assignment is to be able to read two files, a dictionary file, and a file you want to spell check. I've also attached the test files too.
When reading small files where there is only one word per line it works fine. But when I try to test a paragraph it returns all the words as misspelt.
Here are all of the classes that were given for this assignment. I've made some modifications to try to get them to work properly.
BinarySearchTree.java
// ADT binary search tree. // Assumption: A tree contains at most one item with a given search key at any time.
public class BinarySearchTree extends BinaryTreeBasis { // inherits isEmpty(), makeEmpty(), getRootItem(), and // the use of the constructors from BinaryTreeBasis
[Code] .....
As you can see I read in the dictionary file and the spellcheck file, construct a new BST, and then insert each word from the dictionary into the tree.
Then I make an empty arraylist for the misspelt words. While searching through the spellcheck file, if it finds any incorrect words, it adds them to the list then returns the list after it's done reading through the file.
But for some reason it prints out every single word in the test file and I can't figure out why.
How to do draw the original binary tree based on traversal results?
A binary tree has this pre-order traversal result: A,B,D,H,I,E,F,C,G,K,J (TreeNodes) And the same tree gives the following in-order traversal: B,H,I,D,A,C,F,E,K,G,J. Can you draw the tree structure?
I've been working on a program where you can interact with the computer and play a guessing game of numbers between 1 and 100. It's mainly finished, I just need to add in my comments and stuff. My one problem about it that I cannot figure out is trying to get the results to give the correct int. At the end of the game, it's supposed to return the user information about how well they did like this:
Overall results: total games = int total guesses = int guesses/game = double best game = int
best game should give you the least amount of guesses you had during a particular round of the game. Here is what I have so far:
import java.util.*; public class Guess { public static final int MAX = 100; public static void main(String[] args) { intro(MAX); Scanner console = new Scanner(System.in); int tempBestGame = 0;
I develop a little app in javaee6 and jsf2. I have a search page which has a search form with 2 fields and a search button when i click search button the results should be displayed in searchresults page.
Issue: searchresults page is is not displaying records though it fetched records from table I'm able to achieve this using search bean as session scope but i want to use the scope as Requestscope.
I am using a GUI to display search results based on user's input server name. I am using MS Access as DB and I have the DSN set up correctly.But the search results are displayed for the first typed value in text filed. I am getting same result set every time though i input different server names .
import java.sql.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; import javax.swing.table.DefaultTableModel; public class SearchResult implements ActionListener{
I wrote a java program for my gui number converter app, the main purpose of this program is to make sure that user enters only a binary number for conversion from binary to other number formats. the problem is my program keeps prompting me to enter correct binary number, no matter if i enter correct binary number, it will still keep prompting me to enter correct number. Here is the code
import java.util.*; public class test { Scanner key = new Scanner(System.in); String in; int b; public test()
So everything in my program is working EXCEPT when it comes to calculating the result. I am supposed to evaluate the expression using postorder traversal to return the answer. I am honestly not sure how I would get the postorder traversal to return the answer to the expression since the only thing we really went over was how it re-ordered the expression so that it would end in the postorder/postfix order. Anyways, currently the way that I have the public int evaluate(Node node)method set up is giving me a result of 0, which obviously is not correct.
Here's the section that I'm having issues with:
public int evaluate(Node node){ if(node.isLeaf()){ return Integer.parseInt(node.value); } int result = 0; int left = evaluate(node.left); int right = evaluate(node.right);
I have a list of people with a matching telephone extension number, the people are organised in a hierachy tree with some colleagues at the same level and then some junior colleagues. I have been trying to write code that can find the tree height of any given member but I am unable too. Here is my code so far but the left and right are not working because I have not declared them any where in my code.
Java Code:
//hierarchy rank section 7 // **Depth** from node to root (bottom up) public int rank(Member p1){ //to do
We have this piece of code and we must make a search for a key. if the key exist it returns true if not false. Plus we must insert a key in the class. If it is already in there we say hey its already in and we don t put it again...
package askisi2; import java.util.*; public class mtree { protected class tnode { public int k1; public int k2; public int k3;