Answered step by step
Verified Expert Solution
Question
1 Approved Answer
import java.util.Random; class SkipListNode { int value; SkipListNode [ ] next; public SkipListNode ( int value, int level ) { this.value = value; this.next =
import java.util.Random;
class SkipListNode
int value;
SkipListNode next;
public SkipListNodeint value, int level
this.value value;
this.next new SkipListNodelevel ;
public class SkipList
private static final int MAXLEVEL ;
private int level;
private final SkipListNode head;
private final Random rand;
public SkipList
this.level ;
this.head new SkipListNodeIntegerMINVALUE, MAXLEVEL;
this.rand new Random;
public void insertint value
int newLevel randomLevel;
SkipListNode newNode new SkipListNodevalue newLevel;
SkipListNode update new SkipListNodeMAXLEVEL ;
SkipListNode current head;
for int i level; i ; i
while currentnexti null && current.nextivalue value
current current.nexti;
updatei current;
for int i ; i newLevel; i
newNode.nexti updateinexti;
updateinexti newNode;
if newLevel level
level newLevel;
public boolean searchint value
SkipListNode current head;
for int i level; i ; i
while currentnexti null && current.nextivalue value
current current.nexti;
current current.next;
return current null && current.value value;
private int randomLevel
int randomLevel ;
while Mathrandom && randomLevel MAXLEVEL
randomLevel;
return randomLevel;
public static void mainString args
SkipList skipList new SkipList;
int values ;
for int value : values
skipList.insertvalue;
System.out.printlnArama sonular:;
for int value : values
System.out.printlnvalue bulundu mu skipList.searchvalue;
BU KODDA private final Random rand; KISMINDA VARABLE RAND S NEVER EEAD HATASI ALIYORUM VE BU YUZDEN KODUM ALIMIYOR NE YAPMAM GEREK
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started