Question: 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

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!