How To Search For Two String In BST

May 6, 2015

I'm Trying to write a method that search for two String from node class and return the value but when i run it

Exception in thread "main" java.lang.NullPointerException

This is the code :

public Node findName(String firstName, String lastName) {
return findName(root, firstName,lastName);
}
private Node findName(Node p, String first,String last) {
if (p == null) {

[Code] .....

View Replies


ADVERTISEMENT

Binary Search For String

May 26, 2015

I have problem in searching for the words from my text file.. im using binary search technique

private boolean doSearchQuery(String searchQuery) throws IOException {
Log.i(TAG, "in doSearchQuery, query string: " + searchQuery);
boolean result = false;
toSort = new ArrayList<String>();
myTv = (TextView) findViewById(R.id.myFile);

[Code] .....

View Replies View Related

String Search In File?

Aug 12, 2014

I am inputting a file that has the system output when pinging an ip address. i have gotten it to read the file into an arraylist with readLine. Is there a way to have it input to list using spaces instead of lines?

BufferedReader bf = new BufferedReader(new FileReader(file));
int linecount = 0;
int numberTimes = 0;
String line;
//loop thru file and add contents to an arraylist
while ((line = bf.readLine()) != null) {
inLine.add(line);
}
bf.close();
System.out.println(inLine);

get the arraylist to hold it like this:

(0)Pinging
(1)192.168.1.6
(2)with
(3)32
(4)bytes
(5)of
(6)data

View Replies View Related

How To Compare String In Binary Search Tree

Aug 31, 2014

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;

[Code] ....

View Replies View Related

Unique Method To Search A Character In String

Oct 14, 2014

Which string method to search a particular character in a string whether a particular character is there or not . Suppose my String is like............

String s = "Java.";

How I can find the character " . " in above string "Java." is present or not . What is the string method to search that "."

View Replies View Related

String In Java - Search Text On Document For A Word

Feb 5, 2014

Consider in a Document if a String " Hello" is Encoded and stored as "XYZAB"

I want to search the text on document for a word "Hello" and Replace the word with "HelloWorld"

The Program will encrypt the word "Hello" and Search the file then return the encrypted code as "XYZAB" Found

Now i have to replace the word "Hello" with "HelloWorld" in encrypted form so that the Letter "XYZABEFGHI" is replace in the place of Hello where "World" is encoded as "EFGHI"

Now the Problem is If there is more number of occurrence of the word "Helloworld" exist in the file... How can i Replace only one particular occurrence What can be done to select the particular occurrence.

I have attached my java program for Encryption along with this mail for your ease of use.

View Replies View Related

Search For A String In Large Text File Of 1 GB Size And Print Line When Match Found

Feb 18, 2014

I have a large text file of 1 GB size. I need to print the line when a matching word is found in a particular line. Below is the code I am using. But if there are many lines that has the matching word, it's taking lot of time. Any solution to print the lines much faster.

Scanner scanner = new Scanner(file);
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
if(line.contains("xyz")) {
System.out.println(line);
}
}

View Replies View Related

Ability To Search A Binary Search Tree And Return The Number Of Probes

Sep 1, 2014

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) {

[Code]....

View Replies View Related

Creating Search Method For Binary Search Tree

Apr 22, 2014

I want to create a search method that returns the frequency of a word in the search method.

public class IndexTree {
private class TreeNode {
TreeNode left;
String word;
int frequency;
TreeNode right;

[Code] .....

View Replies View Related

How To Add A Search Function

Jul 11, 2014

I'm trying to create a booklist in java using swings but I'm facing a problem. I don't know how to add a search function to my list. I need a search box with the book names.

View Replies View Related

How To Put Search Bar In Program

Oct 21, 2014

how to put search bar in my program.i am just new to java programming so i dont really master all the codes.i dont have much time

import java.io.*;
import java.util.Scanner;
public class myjavProject{
public static void main(String[] args)throws IOException{
PrintWriter output = null;
String ID;
String firstname;
String lastname;
String ans = "y";
String userinput;

[code]....

View Replies View Related

Treemap Partial Key Value Search

Apr 3, 2015

Knowing that a hashmap does not sort the keys, I am thinking of using/converting to treemap which by nature does sort out the keys. I now need to find out if it is possible to search a treemap using partial keys such that for example I would like to search for all entries that have a key starting with "78BOX" whilst the available keys are:

75SQUARE3
76DIAMOND2
78BOX26
78BOX99
78BOX300
79TRIANGLE4

The above list is probably how treemap would sort out the keys however need to extract only those keys that start with "78BOX" - does treemap has this functionality ?

View Replies View Related

Search For Key In Integer Array?

Jun 29, 2014

// 1 ***** student writes this method
/** Searches for key in integer array named arr
// arr is an instance variable of the class and has been instantiated and filled with random values.
// @param key value to search for
// @return if key is found, the index of the first element
// in array whose value is key; if key is not found,
// the method returns -1
*/

public int sequentialSearch( int key ) {
// Note: To animate the algorithm, put this method call as the first statement in your for loop
// animate( i, 0 );
// where i is the index of the current array element
return 0; // replace this statement with your return statement
} // end of sequentialSearch

[Code] ....

View Replies View Related

2D Arrays - Word Search?

Dec 14, 2014

Okay, so the assignment was creating a word search for the given array. I've created all the code necessary, but I've ran into trouble. This problem occurs with the Up-Forward, Up-Backward, Down-Forward, and Down-Backward sections. If I only set one of these to run, it works. But if I have all 4 set at the same time, it errors out on the first one that runs.

public class P_WordSearch {
public static void main(String[] args) {
char[][] puzzle = {
{'B','O','O','G','S','R','O','W','I','N','G'},
{'E','B','L','G','N','I','M','M','I','W','S'},
{'L','C','E','A','T','I','P','U','P','I','S'},
{'C','M','I','N','C','A','X','Y','O','S','N'},

[Code] ....

View Replies View Related

234 Tree Search And Insert

Apr 15, 2014

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;

[Code] ....

View Replies View Related

Search Code Error

Jan 14, 2015

I am pretty new to Java and I am working on a sample Search code from my textbook. I can't figure out why I am getting the following error because I copied the sample exactly as it is in the book. The error is illegal start of expression on the second to last line.

public class Search {
public static final int NOT_FOUND = -1;
public static int binarySearch( int [] a, int x )
{
int low = 0;
int high = a.length - 1;
int mid;

[code]....

View Replies View Related

Binary Search Algorithm

Mar 24, 2014

I am trying to make a program that compares the 3 different search algorithms(sequential/binary/hashing). I have already made the sequential search algorithm, binary and hashing part of the code.My program OPENS a data file, and then OPENS a key data file. and then searches through them using both. How to go about the binary and hashing search algorithm (in the driver program).

*I have included a zip file with:
-base program
-driver program
-data file
-key data file

View Replies View Related

Implementing Breadth First Search

Dec 13, 2014

I have always wanted to program A*, Breath First Search and Depth First Search ever since I took AI. I will only post BFS at the moment but it is only searching the row.

Java Code:

//Breath First Search. The first node passed to it is the start button
void bfs(Mybuttons button){
Queue<Mybuttons> q = new LinkedList<Mybuttons>();
q.add(button);
button.setIcon(button.setButtonToBlueWhileSearched());
button.model.visted=true;

[Code] ....

Output:

Java Code: In while loop
In get Child Node
In get Child Node
In get Child Node
In get Child Node
In while loop
In get Child Node
In get Child Node
In get Child Node
In while loop
In get Child Node
In get Child Node
In while loop
In get Child Node mh_sh_highlight_all('java');

View Replies View Related

Linear Search Of Arraylist By Last Name

Nov 5, 2014

I am having some trouble with linear search of a customers last name. I can't seem to get it to work. I have looked up examples but cant find many with Array Lists. Here is my code.

import java.util.ArrayList;
import java.util.Scanner;
public class AccountDriver {
public static void main(String[] args) {
ArrayList<Account> al = new ArrayList<Account>();
ArrayList<Customer> cust = new ArrayList<Customer>();
Scanner scan = new Scanner(System.in);

[code]....

View Replies View Related

Binary Search With Compare To

Apr 26, 2015

package bisecsearchsmccr;
import java.util.Random;
public class BisecSearchSMcCr
{
public static void main(String[] args) {
String[] names =

[Code] ....

I get this error:

run:
Johann
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 41
at bisecsearchsmccr.BisecSearchSMcCr.bisect(BisecSearchSMcCr.java:72)
at bisecsearchsmccr.BisecSearchSMcCr.main(BisecSearchSMcCr.java:42)
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)

View Replies View Related

Java GUI Search And Update

May 15, 2015

I'm trying to make a update page where you search for person info by their number then have the ability to change any info and save it back to the binary field. I have the search working but i don't know how to do the update,.here my code:

Java Code: import javax.swing.*;

import java.awt.*;
import java.awt.event.*;
import java.io.EOFException;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;

[code]....

View Replies View Related

EJB / EE :: How To Search Items In ArrayList

Jan 26, 2015

I try to create a jsf project within ejb which is add new car with entering attributes listing attributes and search by make.

Add and list methods working well , but have problem of list method. I tryed many combinations (using enhanced loop, iterative loop) but i cant provide working well. Always outputText returns nothing ,when i enter attributes.

Here is ejb code for adding ,getting and listing car items :

@Stateful
public class CarsBusiness implements CarsBusinessLocal {
List<Car> cars;
public CarsBusiness() {
cars = new ArrayList<Car>();

[Code] .....

View Replies View Related

Binary Search With 3 Subsets

Apr 20, 2015

I have created a binary search with 3 subsets, some aslo call it a ternary search and have come up with a minor problem. If you run the code as posted below it just runs until you quit it. If anyother value in the array is searched it is found.

/*
public class BinarySearchDemo {
public static void main(String[] args) {
String[] songs = {"Ace Of Spades", "Beyond the Realms Of Death", "Breaking The Law",

[Code].....

View Replies View Related

Binary Search Error

Dec 7, 2014

How do I make it so I am able to enter any number rather then just the numbers in the arrays? I want it to be able to find the position of any number between 0-100.

import javax.swing.*;
public class BinarySearch {
public static void main(String[] args) {
int array[] = new int[11];
array[0] = 10;
array[1] = 20;
array[2] = 30;
array[3] = 40;
array[4] = 50;
array[5] = 60;

[code]...

View Replies View Related

Binary Search - Get To Int X Int Y In A Grid That Is N By N

Sep 15, 2014

The point is to use a binary search to determine how many steps it would take to get to int X, int Y in a grid that is N by N. Picture a parking lot that is square and your car is at (x,y). You can honk your horn from your key to determine the direction of the car. I need to return the amount of steps to get to the car. You can't step diagonally. I am currently getting an error that causes an infinite loop and I can't fix it.

public class ParkingLot {
public int search(int N, int X, int Y) {
int minX = 0, maxY = N, minY = 0, maxX = N;
int num = 0;
int curX, curY;
int newCurX, newCurY;
curX = (minX + maxX)/2;
curY = (minY + maxY)/2;
while (curX != X || curY != Y)

[code]....

View Replies View Related

Breadth First Search Traversal

Dec 5, 2014

This method uses BFS traversal on a vertex and displays the values. I have worked this out on paper and 2 out of 3 the results from my code match my work on paper. I believe the error is that it prints out 3's adjacent child before 3 itself. I have attached the results I did by hand. Here's the graph and results from my code:

0 1 2 3 4 5
------------
0| 0 1 1 0 0 0
1| 0 0 0 0 0 0
2| 0 0 0 1 0 0
3| 1 0 0 0 0 0
4| 0 0 1 0 0 1
5| 0 1 0 1 0 0

BFS:
5 1 3 0 2
4 2 5 0 3 1 //i think this is wrong. shouldnt it be 4 2 5 3 1 0?
0 1 2 3

Here is my code:

public void bfsTraversal(int vertex){
Queue<Integer> q = new LinkedList<Integer>();
visited[vertex] = 1;//mark vertex as visited
q.add(vertex);
System.out.print(vertex + " ");

[Code] .....

Attached image(s)

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved