Question: Why am I getting this error message? My BinarySearchTree class works so I know the problem is with the SortedListLinked class. The SortedListLinked code is

Why am I getting this error message?

Why am I getting this error message? My BinarySearchTree class works so

My BinarySearchTree class works so I know the problem is with the SortedListLinked class. The SortedListLinked code is below.

////////////////////////////////////////////////////////////////////////////

public class SortedListLinked { private Node head; private int size;

public SortedListLinked() { head = null; size = 0; }

public boolean isEmpty() { return (size == 0); }

public int size() { return size; }

public KeyedItem remove() { //DO THIS //remove the smallest item if(head == null) return null; KeyedItem itm = (KeyedItem)head.getItem(); head = head.getNext(); size--; return itm; }

private Node locateNodeAdd(KeyedItem item) { //DO THIS //find the insertion location (remember FIFO for duplicates) Node curr = head; Node prev = null; String itm1 = item.getKey(); KeyedItem k = (KeyedItem) curr.getItem(); String itm2 = k.getKey(); //keep looking until the it find the correct insertion spot

while(curr != null && (itm2.compareTo(itm1)) >= 0) { prev = curr; curr = curr.getNext(); k = (KeyedItem) curr.getItem(); itm2 = k.getKey(); } return prev; }

public void add(KeyedItem item) { Node prev = locateNodeAdd(item); if (prev == null) { //insert the new node containing the new item at the beginning of the list Node node = new Node(item); node.setNext(head); head = node; } else { //insert the new node containing the new item after the node that prev references Node node = new Node(item); node.setNext(prev.getNext()); prev.setNext(node); } size++; } }

C: WINDOWS system32 cmd.exe [mkdir] Created dir C:\progi starting files build build [javac Compiling 23 source files to C: prog starting files build [javaj Excel ion in thread main" java lang.Null PointerException [java at pqsort. SortedListLinked.locateNodeAdd (Unknown Source) [java at pqsort.SortedListLinked.add(Unknown Source) [java at pqsort.PQSLL.pqInsert (Unknown Source) [java at pgsort.PQSort.pqsort(Unknown Source) [java at cds CDSort main (Unknown Source BUILD FAILED C:\progi starting files build.xml :33: Java returned 1 Total time: 1 second C:\progi starting files

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!