Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Im Writing a generic skip list in java and I call this function int the class Node /* An O(1) method that returns a reference

Im Writing a generic skip list in java

and I call this function int the class Node

/* An O(1) method that returns a reference to the next node in the skip list at this particular levels. Levels are numbered 0 through (height minus 1), from bottom to top. If levels is less than 0 or greater than (height minus 1), this method should return null. */ public Node next(int level){ System.out.print(" "+level); if(level<0 || level>2){ return NULL; //this is Node NULL = null; } return foward.get(level); }

from public class SkipList >

like so:

Node next2 = head.next(3);

this causes the program to crash declaring "NullPointerException " BUT prints this:

System.out.println(head.next(3));// prints out null

no problemo

Whys it not working? and how do I fix it?

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

Filing And Computer Database Projects

Authors: Jeffrey Stewart

2nd Edition

007822781X, 9780078227813

More Books

Students also viewed these Databases questions