Sequential Search For Two Data Variables In Linked List

May 5, 2014

I just trying to find the most efficient way to do this. I read in a csv file into a linked list and then I split the linked list into sections based on category for each element. Of course I used an array to split each element of the list. However I can do the sequential search by either ID and Name by using hashmap and making the key = name + ID and then doing key.contains(charSequence);. However I feel like this is inefficient and I would like to use the linked list instead of a hashmap which could be done by splitting the user input and used for method overloading by passing an int in one and a string in another. I feel like this approach is a little more redundant and maybe their is a better approach for searching for id and name. Below is an example of the elements in a linked list.

note: their are more elements than this.

element 1

name: George
address: 4410 something dr.
phone number: 978-888-6666
id: 43

element 2

name: Karla
address: 339 something dr.
phone number: 334-338-6556
id: 23

View Replies


ADVERTISEMENT

How To Traverse And Search For Element In Linked List

Nov 11, 2014

I have to make a method called search that goes through the linked list and checks to see if whatever String the user entered matches a String in the linked list. With this code, every time I enter an existing String it outputs "There is no element that contains that information". How come?

public class LinkedListExample {
List InfoList = new LinkedList();
public void doLinkedListExample()
{ // add original data to linked list
InfoList.add("Computer"); // string (original 3 elements)
InfoList.add("Programs");
InfoList.add("in Java");
 
[code]....

View Replies View Related

Sort Linked List Through The Nodes Of List - Data Of Calling Object

Feb 14, 2014

I have some class called sorted to sort the linked list through the nodes of the list. and other class to test this ability, i made object of the sort class called "list1" and insert the values to the linked list.

If i make other object called "list2" and want to merge those two lists by using method merge in sort class. And wrote code of

list1.merge(list2);

How can the merge method in sort class know the values of list1 that called it as this object is created in other class.

View Replies View Related

Binary And Sequential Search?

Dec 10, 2014

Righto, so I've crafted a binary search and a sequential search. The sequential search works perfectly fine.

However; my binary search doesn't. If I enter in incorrect data, it tells me the data I entered was incorrect. But if I enter in correct data, my sequential search tells me my datas correct, but binary search tells me I'm still incorrect. Here's my binary search + the test program.

public class ValidatorWilson
{
int[] accountNumbers = {5658845, 4520125, 7895122, 8777541, 8451277, 1302850,
8080152, 4562555, 5552012, 5050552, 7825877, 1250255,
1005231, 6545231, 3852085, 7576651, 7881200, 4581002};

public boolean partTwo(int numberCheck)
{
if (accountNumbers.length == 0)

[Code] ....

View Replies View Related

Nodes Contain Array Data Sets In A Linked List?

Mar 9, 2014

TL,DR: observe the nodes just below, that is the data each node in the link list contains. How do I iterate through the entire list to reach the last element (H), so I can add an element right after it?

So I have 4 nodes doubly linked with two dummy nodes for head and tail:

head
node1 = {A}
node2 = {null, B}
node3 = {C, null, D, E}
node4 = {null, F, null, G, null, null, H, null}
tail

Ok, so since the list only contains 8 elements that are not null, its size is actually 8 correct? So now lets say I have an add method that has

add(E item) and inserts the item at the end of the list. So I can get to the last node with tail.previous(), but then how do I iterate to the end so I can add the item after the last item in the list (H). I guess I don't know how you only access one nodes data when that data is an array with empty spaces.

Here is the entire Node code:

Also, I can't just iterate through the whole thing because I am not supposed to. I am supposed to just find the right node and iterate through that only.how to maneuver around a linked list containing nodes where each node contains an array.

/**
* Node class that makes up a DoublingList. Feel free to add methods /
* constructors / variables you might find useful in here.
*/
public class Node<E> {
 
/**
* The node that comes after this one in the list

[code]....

View Replies View Related

Traverse Linked List From First To Last Node And Print Data Value

Jan 1, 2015

AddItemToFront(Item p) : This method will create a new Node with the Item object as its data value and then add the newly created node to the front of the linked list.

DisplayItems(): This method will traverse the linked list from first node to last node and print data value ( i.e., id, name, type and price of the Item object) of each node.

RemoveItemAtPosition(int n): This method will remove the node at position n in the linked list. Assume that the first node of the linked list has a position number of 1 and the second node has a position number of 2 and so on.

This is my Code

AddItemToFront
public void AddItemtoFront(Item p)
{
Node newNode = new Node(p);
newNode.setLink(head);
head = newNode;

[Code] ....

I don't know what am I suppose to do inside the remove method

View Replies View Related

Method That Print Data Of Single Linked List Backward Using Stack

Apr 23, 2015

I am trying out solving the question but i am stuck.The problem is to write a method that print data of single linked list backward using stack.The question is as follow

public class Stack{
public boolean isEmpty(){};
public void push(int n){};
public int peek(){};
public int pop(){};
}

public class node{
int data;
node next;
}

public class list{
node first;
}

View Replies View Related

Building Linked List Whose Nodes Data Is The Sum Of Nodes Of Other List

May 1, 2014

public void add(int d){
listNode l = new listNode (d, null);
l.next = first;
first= l;

public list Sum2List (list l1, list l2){
//variables
int sum;

[Code] .....

But I have a problem in my first listNode where it ll be pointing to null, thus in the sum2List method the program checks the while condition into false and doesn't go through the loop.

View Replies View Related

Writing A Sequential Data File?

Dec 15, 2014

I need to write a program that, when a button is pressed, will add the user input to a table AND write it to a sequential data file. I have everything done accept for how to write the data sequentially(all input data on the same line in the file). The following is part of the code:
 
private void submitButtonActionPerformed(java.awt.event.ActionEvent evt) {
DefaultTableModel dtm = (DefaultTableModel)jTable1.getModel();
dtm.addRow(new Object[]{donorName.getText(),charityName.getText(),donationAmmount.getText()});
//Adds user input to the table 
try
{
FileWriter writer = new FileWriter("FundraisingInformation.txt",true);//Creates file or adds to it
  BufferedWriter bw = new BufferedWriter(writer);

[code].....

I would need the file output to be in the following format:

donorName charityName donationAmmount

As I said, using the .write(bw) i know how to make it look like:

donorName
charityName
donationAmmount

View Replies View Related

Linked List Implementation Of List Interface?

Oct 5, 2013

So we have an assignment regarding a linked list implementation of a given list interface.

In my list interface, the method contains(T anEntry) is defined.

In the LList implementation, contains is already implemented as part of getting the core methods in.

Now I am being tasked with the following:

Provide a second implementation of the method contains2(T anEntry) that calls a private recursive method

Private boolean contains (T anEntry, Node startNode) that returns whether the list that starts at startNode contains the entry anEntry.

I've written the private recursive method already. That's not an issue (at least not right now).

But what I don't understand is how startNode is supposed to be populated when this private contains method is called from the public contains2 method? contains2 only takes one parameter: anEntry. the private method takes two parameters: anEntry and startNode. How am i supposed to provide startNode when I am calling contains2?

View Replies View Related

Linked Binary Search Tree - Creating Node Object

Apr 5, 2015

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>

[Code] ....

View Replies View Related

Code To Search For Static Variables That Look Like Username Or Password

Sep 24, 2014

a code to search for static variables that look like username or password.i want to be able to search through a source code for such variables.

View Replies View Related

List Interface Class That Has Operations For Linked List And LList Class

Oct 6, 2014

I have this ListInterface class that has operations for my linked list and a LList class. The Llist and ListInterface classes are perfect. My job is to create a driver, or a demo class that showcases these operations. That being said, heres the driver so far:

import java.util.*;
public abstract class DriverWilson implements ListInterface
{
public static void main(String[] args)
{

LList a = new LList();

[code]....

View Replies View Related

Inserting A Set Into Linked List?

Mar 21, 2014

What I'm supposed to do is make a method to insert a set of Tiles to the list,i.e.,a detour(make sure that the inserted detouris compatible with thecurrent path so that the resultingpathdoesnot have any gaps). But I'm confused on how to go about doing it. I was thinking of maybe just adding 1 to the current Node.

import java.io.File;
import java.io.FileNotFoundException;
import java.util.List;
import java.util.Scanner;
public class Path {
static Tile startTile;

[code].....

View Replies View Related

Dynamic Linked List

Jan 30, 2014

I'm trying to implement an Office class that contains an inner class: WorkerNode. The WorkerNode class has a name attribute (String) and WorkerNode attributes for boss, peer and subordinate. The attributes of Office are manager and current which are WorkerNode references. The manager refers to the entry point of the structure and current is the current node in the structure. For simplicity, i'm going to try to limit it to 3 levels and assume that the names are unique. I've put together a Office class that containing main and provided the code I've worked on so far.

public class Office {
public static void main(String[] args) {
String name=Input.getString("input the manager's name: ");
Office office=new Office(name);
int option;

[code]....

View Replies View Related

Linked List Sorting

Apr 20, 2014

I have made a node class and im trying to implement a sorting method. I must use a selection sort but with specific instructions: "Your method should not need to use the new operator since it is just moving nodes from one list to another( not creating new nodes)

this is my current implementation ..but i am instantiating new object..

public class NodeInt
{
private int data;
private NodeInt next = null;
public NodeInt(){}
//precondition:
//postcondition:
public NodeInt(int data, NodeInt next)
{
this.data = data;
this.next = next;

[code]....

edit: this is the part that worked but i had it commented out so i have the previous and current declared above but didnt copy.

View Replies View Related

Searching Linked List

Apr 30, 2014

Ok here I have a code that generates 1 million random values then converts them to a string then hashcode. I then insert into a linked list and then I want to run through each hash and find it in the linked list timing each run then averaging out the time at the end.

It works great for smaller amounts of numbers it is searching for (fine under 50 thousand searches for the for loop starting at line 24 LinkedListTest.java) but when I try to do the full million searches it gives me "a Exception in thread "main" java.lang.StackOverflowError" at line 158 in List.java. Maybe im getting tired but I cannot figure out why.

// class to represent one node in a list
class ListNode< T >
{
// package access members; List can access these directly
T data; // data for this node
ListNode< T > nextNode; // reference to the next node in the list

[code]....

View Replies View Related

Add Or Remove Will Be More Efficient By A Linked List

Jan 31, 2015

if one address point on another address. so set and get methods will be less efficient then an array, but add or remove will be more efficient by a linked list ? a linked list also inherit from queue so if i add an elemnt via "addFirst" function . where its adding the element ? to the right most or left most ?
if i have for example :

here [ ] --> [ ] --> [ ] --> [ ] -->[ ] or here

linked list its FIFO so the head will be the right most ?

Edit : its confused me a little bit but i understood now .so it will be at the left most. its actually ordered . not like the stack which is LIFO.

View Replies View Related

Sort Singly Linked List

Oct 30, 2014

I searched a lot but can't seem to understand the sorting of a SLLNode... I noticed a method called Bubble Sort, I understand how it works, but can't think of a way to implement it to my code..

View Replies View Related

Insert Method Of Linked List

Dec 30, 2014

Is there a particular implementation of a linked list you are referring to in your question?

View Replies View Related

How To Move Along A Doubly Linked List

Dec 11, 2014

I'm having some trouble with figuring out how to move along a doubly linked list for an assignment. The program is supposed to be a simple board game simulation. Here is what I have so far:

Space.java:

public class Space
{
private String name;
public Space next;
public Space previous;
public Space(String name)
{
this.name = name;

[Code]...

I seem to have been able to get all the other methods working properly, but I am pretty stuck on how to do the movePlayer. Specifically because it is passing an integer, but my objects are of type Space and Boardgame.

View Replies View Related

Recursively Reverse Linked List?

Oct 17, 2014

i tried everything but its giving me errors. i tried the for loop but its giving me something else.

this is what i have to do Write a recursive method that prints out the data elements of a linked list in reverse order.

Your method should take in as a parameter the head reference to a linked list. Then, write a recursive method that returns a count of the number of elements greater than a given threshold. You may assume that the data elements in the linked lists are ints. The parameters of your method are a reference to the linked list and a int value representing the threshold.

public class recursion3
{
public static void main(String [] args) {
char a [] = {'A', 'B','C','D','E'};
System.out.println(a);
}
public static String reverseString(String s) {
if (s.length() <= 1) {

[code]....

View Replies View Related

Printing Contents Of Linked List

Feb 17, 2015

I'm trying to print the contents of my linked list. I'm using nodes and within those nodes it hold String data. So i want to print out the data within the nodes. Whenever i do

System.out.println(node1.data),

it prints perfectly. But i'm trying to use a method where it would loop through the list and print out the data for every node in it. when i run my print method i get results such as

Node@15db9742
Node@6d06d69c
Node@7852e922.

Here is my print method i created

Java Code:

public void print(){
Node<E> current = head;
while (current.next != null){
System.out.println(current.data);
current = current.next;
}
} mh_sh_highlight_all('java');

View Replies View Related

Java Linked List Reverse

Apr 12, 2014

I am creating a recursive method to reverse a linked list in java. It works the first time when I call it, but I want it to work where I call it a second time and it reverses it to the original state. How can I get that to work with this implementation?

public void reverseList() {
System.out.printf("%-16s%-3s%n", "Name", "Score");
System.out.println("--------------- -----");
reverseList(first);
} public void reverseList(Node aNode) {
if (aNode != null) {
reverseList(aNode.next);
System.out.printf("%-15s%6s%n" , aNode.name , aNode.score);
}
}

View Replies View Related

How To Advance To Next Node In Linked List

Apr 7, 2014

I am trying to advance to the next node in my linkedList. Below is what i have so far.

/**
* Move forward, so that the current element is now the next element in this sequence.
* @param - none
* @precondition:
* isCurrent() returns true.
* @postcondition:
* If the current element was already the end element of this sequence (with nothing after it), then there is no longer any current element.
* Otherwise, the new element is the element immediately after the original current element.
* @exception IllegalStateException
* Indicates that there is no current element, so advance may not be called.
**/

public void advance( ) {
// student implements
if(!isCurrent())
throw new IllegalStateException();
else{
while(cursor != null){
precursor = cursor;
cursor = cursor.getLink();
}
}
}

View Replies View Related

Updating Specific Value In Linked List

Feb 18, 2014

I create and populate someLinkedList with '*' characters as soon as a gameLinkedList object is created, so my class is something like

private int size;
public class gameLinkedList{
private CharNode game;
public gameLinkedList(String someWord){
size=someWord.length();
for(int i=0;i<size;i++){CharNode aNode = new CharNode('p');

[Code] .....

View Replies View Related







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