Linked List Sort - ToString Returning Null

May 22, 2014

import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedList;
import java.lang.Comparable;
import java.util.*;
import java.lang.*;
public class MyLinkedListSort {

[Code] .....

Output is :

name is nulland salary is0
name is nulland salary is0
name is nulland salary is0
name is nulland salary is0

Expected output :

Name is Crish Salary: 2000
Name is Tom Salary: 2400
Name is Ram Salary: 3000
Name is John Salary: 6000

Where i going wrong

View Replies


ADVERTISEMENT

Linked List Queue ToString Method

Oct 21, 2014

So I have to write all the methods for a LinkedListQueue. I've got isEmpty, enqueue and dequeue working correctly (I think) but I'm having trouble with the toString method. I tried to do it recursively and it works if there is only one element in the list, but with multiple elements it throws a StackOverflowerror exception. I've tried it multiple different ways, but I can't seem to figure out how to print it out with out clearing everything. We haven't been taught StringBuilder or .append yet, which I saw a lot of as I was looking for solutions, so I can't use those.

public class LinkedQueue<T>
{
protected LLNode<T> front; // reference to the front of this queue
protected LLNode<T> rear; // reference to the rear of this queue
private T info;
public LinkedQueue()
{
front = null;
rear = null;

[Code] ....

and this is the ITD used with it, for some reason it has the "empty the queue" function as a choice but we weren't assigned that function, so just ignore it.

import java.util.Scanner;
public class ITDLinkedQueue
{
public static void displayMenu()
{
System.out.println("(1) display menu");
System.out.println("(2) check isEmpty");
System.out.println("(3) enqueue");
System.out.println("(4) dequeue");

[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

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

Merge Sort Java And Linked List?

Dec 11, 2014

I've playing around with linked lists and methods for sorting. So far I've tested the iterative sort, insertion sort, quick sort and they all worked perfectly. Now, I am trying to implement merge sort that would take a linked list of jobs and sort them according to their priority. I found a few solutions on the web, of which I am trying to implemented this one: LeetCode.

My system is a simple one, I do have a linked list of print jobs, each of which has the priority. The following code should sort my print queue and return the link node of the first sorted element. Here's the code.

//defining a job that has priority
public class Job {
private int priority;

[Code]....

The problem I've been trying to solve is that I am getting the stack overflow at line

ListNode<T> h1 = mergeSort(left);

meaning that I am getting into a loop somewhere down through the process of breaking the linked list into half, half or halfs and so on.

View Replies View Related

Getting Null Pointer Error In Double Linked List Project

May 25, 2014

I am currently making a double linked list class in my compsci class. i was absent for a few days and i need to make an add method for the class. when i go to compile test code i made i get a null pointer error on line 36. This is the node class i wrote and the double linked list class i wrote.

node class

public class Node{
// Two references and Data
Node prev;
Node next;
String data;
public Node(){
prev = null;
next = null;

[Code] ....

This is the class i need working with ( in the doublelinkedlist class)

public void add(Node n){
if(isEmpty()){
first = n;
return;
}
Node temp = first;
while(temp != null){
temp = temp.getNext();
}
temp.setNext(n);
temp.setPrev(temp);
}

View Replies View Related

ToString Returning Last Character Doubled

Apr 27, 2015

To string Returns the last character doubled ... How do i stop it from doubling the last number?

public class CreditCard
{ char c = 0;
public CreditCard(String cardNumber)
{
for( int i=0; i<cardNumber.length(); i++)
{
c = cardNumber.charAt(i);

[Code] ....

View Replies View Related

Why Is Method Returning Null

Sep 25, 2014

I am working on a project which manages an airport's airplanes and flights based on user input. The method printFlights() - lines 133-134 - is returning null and I can't figure out why. The method is supposed to print information about each flight. The logic is identical to the printPlanes() method which is working successfully.

View Replies View Related

GetNextMailItem Keeps Returning Null

Jun 16, 2014

When I try to getNextMailItem,it keeps returning null.Why?

public class MailServer
{
// Storage for the arbitrary number of mail items to be stored
// on the server.
private HashMap<String,ArrayList<MailItem>> mailbox;
/**
* Construct a mail server.
*/
public MailServer()

[Code] .....

View Replies View Related

FileReader - Returning Null

Jan 12, 2014

I'm following a tutorial and I can't work out why the version that I have written is returning null when reading the text file...?

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
public class AppReadFileFileReader {
public static void main(String[] args) {
File file = new File("test.txt");
BufferedReader br = null;

[Code] ...

I can't see any difference in the code though, and the files being found in order for the null to appear... :?

the text file is within the Java project, and just has three lines :

line one
line two
line three

That's all it say..... But all my program returns is the work 'null'

View Replies View Related

Method Is Not Returning Array - Null Error

May 18, 2015

I am trying to return an array and I keep getting a null error. The below class sets the material numbers into an array and should return that array if called :

public class Jobs {
private int[] materialsNumber;
//change to parts and create another class that gets the materials for the parts
 public int[] job1() {
materialsNumber[0] = 11960120;

[Code] ....

I later try to call the method. The program executes but stops after I println "test in loop"

public class PurchaseOrdersToParts {
 private Jobs job = new Jobs();
 int[] getPartsForPurchaseOrder(BigDecimal purchaseOrder) {
 System.out.println("inside getparts");
 BigDecimal testNum = new BigDecimal(123.0);
 
[Code] ....

This is the method that is calling the method in the GenerateOrdersToParts class

private PurchaseOrdersToParts purchaseOrdersToParts = new PurchaseOrdersToParts();
 @Inject
PoRepository poRepository;
public GenerateShopJobTickets() {
 
[Code] .....

View Replies View Related

Black Jack Game - Initiated Object Returning Null

Nov 7, 2014

I've been assigned to create a Black Jack game with a gui. In this game I've created a seperate Player and Dealer class, and both initiated them, however when I try to call a Player object in a certain way I get a null pointer reference. (It should be noted that the Player object is an array)

public void runGame(){
while(running){
while(dealer.getPoints() <=19){
int count=0;

[Code] .....

And this is how I've initilized the Player class in the constructor

Player[] players = new Player[numberofplayers];
for(int i=0; i<numberofplayers; i++){
players[i] = new Player(i);
players[i].setDeck(d1);
gui.add(players[i].getPanel());
}

What I don't get is if I change players[i] to dealer, it works fine.

View Replies View Related

Created Tree Lemur Object - Returning Null Consistently From Methods

May 24, 2015

The question pretty much says it all, but I tasked myself with creating a program about lemurs. There are multiple class files in this program. In the below code snippet, I have my TreeLemur.class which extends to the Lemur.class which extends to the Mammal.class. However, when I create a Tree Lemur object in the main program, it is returning null consistently from certain methods. What am I doing wrong here?

TreeLemur.class :

public class TreeLemur extends Lemur {
private String groupSize;
private String diet;
private String fur;
public void setGroupSize() {
groupSize = "
Group Size: Large";
}

[Code]...

As of yet, I'm just trying to get Tree Lemur working properly to continue with creating the other if-branches within the main program.

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

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

How To Sort A List By Balance

Mar 26, 2014

Add accounts on a list, each account contain: name, accountCode, pinCode, balance.

How to show list sort by balance?

View Replies View Related

Sort Both Array List

Jun 29, 2014

Directions: public static void initialize(ArrayList names, ArrayList sores)

You should write a function that sorts both array lists, based on the values in the scores array list. This is one of the more conceptually challenging parts of the assignment. You want to sort the scores array list, and simultaneously alter the names array list so that the names continue to line up with their respective scores by index. In the example data above, when the score 9900 moves to the first element of the scores array list, the name "Kim" should also be moved to the top of the names array list. The function should have the following signature:

I'm having trouble figuring out how to sort the lists.

import java.util.ArrayList;
import java.util.Scanner;
public class Assignment5
{
/**
*/
public static void main(String[]args) {
intializeArrays();

[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

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

Using Min-heap To Sort List Of Words

May 5, 2015

I am learning to use heaps and as an exercise I am trying to write a program using a heap class I have created to sort words. I have read in words from a file and added them to the heap successfully. I am having some trouble figuring out how I can print out a sorted list of the words. From my understanding of how a min-heap works, if I remove from the min/root node they will always be removed in sorted order. So far I have tried out to do a simple for loop but, only half of the heap is being removed. Not sure if my logic is incorrect of there is an error somewhere in my removeMin() function specifically in the while loop.

public static void main(String[] args) {
Heap heap = new Heap();
heap = read( heap );
for( int i = 0; i < heap.getSize(); i++){
heap.removeMin();

[Code] ....

View Replies View Related

Sort Array List Print?

Nov 23, 2014

I am having an issue trying to print different types of arrays using one method. Eclipse tells me to convert my print method for each array type:

change method 'printList <e>' to 'printList(ArrayList<integer>)'
change method 'printList <e>' to 'printList(ArrayList<Double>)'
change method 'printList <e>' to 'printList(ArrayList<Character>)'
change method 'printList <e>' to 'printList(ArrayList<String>)'

I would like to accomplish printing all four different arrays using one print method. How to accomplish it or provide examples or links to examples?

import java.util.ArrayList;
public class SortArrayList {
public static class Sort {

[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

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







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