This code generates unsorted array. My question is how do I clone the generated array so I can reuse the unsorted array in different sorting algorithms.
public class UnsortedData{
private int [] coreData; private int maxArraySize; private int currentArraySize; public UnsortedData(int size){ this.maxArraySize = size; this.coreData = new int[this.maxArraySize]; this.currentArraySize = 0; } public boolean addData(int data){ if (currentArraySize < maxArraySize) { coreData[currentArraySize] = data; currentArraySize++; return true; } return false; }
public class dataSorting {
public static void main(String[] args) { Random rand = new Random(); UnsortedData uD = new UnsortedData(1000000); for (int x = 0; x < 50; x++) { uD.addData(rand.nextInt(3000000)); } }
https://stackoverflow.com/questions/66147776/how-to-clone-array-in-java-with-this-code February 11, 2021 at 10:02AM
没有评论:
发表评论