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 ; Maksimum seviyeyi belirlemek iin bir sabit
private int level;
private SkipListNode head;
private Random rand;
public SkipList
this.level ;
this.head new SkipListNodeIntegerMINVALUE, MAXLEVEL;
this.rand new Random;
Atlama Listesine bir deer eklemek iin kullanlan metot
public void insertint value
int newLevel randomLevel;
SkipListNode newNode new SkipListNodevalue newLevel;
SkipListNode update new SkipListNodeMAXLEVEL ;
SkipListNode current head;
Her seviyede ilerleyerek eklenecek dmn uygun konumunu bulma
for int i level; i ; i
while currentnexti null && current.nextivalue value
current current.nexti;
updatei current;
Yeni dm uygun seviyelere eklemek ve referanslar gncellemek
for int i ; i newLevel; i
newNode.nexti updateinexti;
updateinexti newNode;
Yeni seviye eklenmise Atlama Listesi seviyesini gncelleme
if newLevel level
level newLevel;
Verilen bir deeri aramak iin kullanlan metot
public boolean searchint value
SkipListNode current head;
Her seviyede ilerleyerek aranan deeri bulma veya bulamama
for int i level; i ; i
while currentnexti null && current.nextivalue value
current current.nexti;
Aranan deeri bulup bulamama kontrol
current current.next;
return current null && current.value value;
Rastgele seviyeler oluturmak iin kullanlan metot
private int randomLevel
int level ;
while Mathrandom && level MAXLEVEL
level;
return level;
public static void mainString args
SkipList skipList new SkipList;
int values ;
Deerleri Atlama Listesine eklemek
for int value : values
skipList.insertvalue;
Arama sonularn gstermek
System.out.printlnArama sonular:;
for int value : values
System.out.printlnvalue bulundu mu skipList.searchvalue;
BU KODDA HATA ALIYORUM VE HERHANG BR IKTI ALAMAIYORUM LTFEN DZELTP TEKRAR ATABLR MSNZ
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