Question: I want the code to be 1 ) in - place quicksort and 2 ) Your algorithm should change the links of the simulated nodes
I want the code to be inplace quicksort and "Your algorithm should change the links of the simulated nodes blue numbers It is not allowed to modify the element of any node red numbers If the input is in the first row, the status after the sorting must be the second row
blue red redo red red red red o redred
blue red redo red red red red o red red
also, do not remove anything from main, and other functions. You can modify but specify what changed. Focus on quicksort, partition, set value, getvalue, getnext.
It has to satisfy all the above. Thank you.
package compa;
import java.util.Arrays;
import java.security.SecureRandom;
public class Main
private int data;
int size;
public Mainint n
size n ;
data new intsize;
data;
for int i ; i size ; i
datai i ;
datasize ;
datasize ;
public boolean isEmpty
return data;
public boolean isFull
return datasize ;
public void err
System.out.printlnOops;
public void insertFirstint x
if isFull
err;
return;
int i datasize ;
datasize datai ;
datai data;
data i;
datai x;
public void quicksort
if isEmpty
int first data;
int last first;
Find the last node
while datalast
last datalast ;
quickSortthis first, last;
public void quickSortMain list, int start, int end
if start end && list.getNextstart end Base case
int pivotIndex partitionlist start, end; Partition the list
quickSortlist start, pivotIndex; Sort left sublist
quickSortlist list.getNextpivotIndex end; Sort right sublist
public int partitionMain list, int start, int end
int pivotIndex start;
int pivotValue list.getValuepivotIndex; Get the pivot value
int i pivotIndex; End of smaller values left partition
int j list.getNextstart; Start iterating from the second node
while j end
if listgetValuej pivotValue
Swap values at i and j and move i forward
i list.getNexti;
Swap values directly without the swapNodes method
int tempValue list.getValuei; Temporarily store node value
list.setValuei list.getValuej; Set node to node value
list.setValuej tempValue; Set node to node value
j list.getNextj; Move to the next node
int tempValue list.getValuepivotIndex; Temporarily store pivot value
list.setValuepivotIndex list.getValuei; Set pivot index to value at i
list.setValuei tempValue; Set i to pivot value
return i; Return the index of the pivot after partition
public int getValueint index
return dataindex;
public void setValueint index, int value
dataindex value;
public int getNextint index
return dataindex ;
public String toString
if isEmpty return "The list is empty.";
StringBuilder sb new StringBuilder;
int i data;
sbappenddatai;
while datai
i datai;
sbappendappenddatai;
return sbappendutoString;
public static void mainString args
int testData
;
for int a : testData
int n alength;
SecureRandom random new SecureRandom;
Main list new Mainn random.nextIntn ;
System.out.printlnThe original array: Arrays.toStringa;
for int i n ; i ; i list.insertFirstai
