Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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?

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases DeMYSTiFieD

Authors: Andy Oppel

2nd Edition

0071747990, 978-0071747998

Students also viewed these Databases questions