Question: Implement a shuffle method that randomly sorts the data. public void shuffle ( long seed ) . This method will take a seed value for
Implement a shuffle method that randomly sorts the data.
public void shufflelong seed This method will take a seed value for use with the Random class. A seed value makes it so the same sequence of "random" numbers is generated every time. To implement this method, create an instance of the Random class using the seed: Random rng new Randomseed; Then, visit each element. Generate the next random number within the bounds of the list, and then swap the current element with the element that's at the randomly generated index.
Here's my current code Im working off of:
import java.util.AbstractList;
public class MyLinkedList extends AbstractList
private Node root;
private int arraySize ;
public boolean isEmpty
return arraySize ;
public int size
return arraySize;
public boolean addE e
if root null
root new Nodee;
else
Node call root;
while callnext null
call call.next;
call.next new Nodee;
arraySize;
return false;
public void addint index, E element
if index
root new Nodeelement root;
else
Node call root;
for int i ; i index ; i
call call.next;
call.next new Nodeelement call.next;
arraySize;
public E setint index, E element
E removed;
if index
removed root.value;
root.value element;
else
Node call root;
for int i ; i index ; i
call call.next;
removed call.next.value;
call.next.value element;
return removed;
public E removeint index
E removed;
Node call root;
if index
removed root.value;
root root.next;
arraySize;
return removed;
else
for int i ; i index ; i
call call.next;
removed call.next.value;
call.next call.next.next;
arraySize;
return removed;
public int indexOfE e
Node call root;
for int i ; i arraySize; i
if callvalue.equalse
return i;
call call.next;
return ;
public E getint index
Node call root;
if index arraySize
for int i ; i index; i
call call.next;
return call.value;
else
return null;
@Override
public String toString
ifisEmpty
return ;
else
return super.toString;
class Node
T value;
Node next;
NodeT val, Node n
value val;
next n;
NodeT val
value val;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
