So I have a little code to compare sorting methods(insertion,merge, etc)
I create a random array of objects where I can specify the size of it. I also have a simple loop to show me the array when created and after it's sorted but if the array size is bigger than 955 elements, it does nothing. What is causing this? I gives me no error. It simply "skips" the printing loop.
Loop in question(I have used a for each version of it too with the same result):
for (int x = 0; x < things.length; x++) {
System.out.print(things[x] + " ");
}
System.out.println();
full code:
public class Root {
private Thing[] things;
private int size = 956;
public Root() {
super();
}
public static void main(String[] args) {
Root root = new Root();
root.go();
}
private void go() {
things = new Thing[size];
long startTime = System.nanoTime();
for (int x = 0; x < size; x++) {
things[x] = new Thing();
}
long endTime = System.nanoTime();
System.out.println("Took " + (endTime - startTime) + " nanoseconds to create the Array of Things");
for (int x = 0; x < things.length; x++) {
System.out.print(things[x] + " ");
}
System.out.println();
startTime = System.nanoTime();
SelectionSort.Sort(things);
// InsertionSort.Sort(things);
// BubbleSort.SortArray(things);
// QuickSort.quickSort(things);
// MergeSorter.SortArray(things);
endTime = System.nanoTime();
for (int x = 0; x < things.length; x++) {
System.out.print(things[x] + " ");
}
System.out.println();
System.out.println("Took " + (endTime - startTime) + " nanoseconds to sort");
}
}