Sorry but I'm having a major brain fart here (guess that's what a few days of little sleep get you). Without changing anything to static how can I make a main() that will run this.
package merger;
import java.util.Random;
public class another {
public int[] numbers;
private final static int size = 100;
private static int maxNumber = 30;
private final static int limit = 10;
public int number;
private boolean Insertion = false;
public void arraytosort(){
numbers = new int[size];
Random number = new Random();
for (int i=0; i< numbers.length; i++){
numbers[i] = number.nextInt(maxNumber);
}
test(numbers);
}
public void test(int[] array){
this.numbers = array;
number = array.length;
mergesort(0,number - 1);
}
public void mergesort(int low, int high){
if(Insertion || high-low < limit){
insertionsort(low, high);
return;
}
if (low<high){
int middle = (low+high) / 2;
mergesort(low, middle);
mergesort(middle +1, high);
merge(low,middle,high);
return;
}
}
public void merge(int low, int middle, int high){
int[] temp = new int[number];
for (int i=low;i<=high; i++){
temp[i] = numbers[i];
}
int i = low;
int j = middle+1;
int k = low;
while (i<=middle || j<=high){
if (temp[i] <= temp[j]){
numbers[k] = temp[i];
i++;
}
else{
temp[k] = temp[j];
j++;
}
k++;
}
while (i<=middle){
temp[k] = temp[i];
k++;
i++;
}
temp = null;
return;
}
public void insertionsort(int low, int high){
for(int i=low+1;i<=high;i++){
int t = numbers[i];
for(int j = i-1; j>=low; j--){
if(t>numbers[j]) break;
numbers[j+1] = numbers[j];
numbers[j+1] = t;
}
}
}
/**
* @param args
*/
public static void main(String[] args){
}
}
I just need to be able to test it to see if this is working. In my head it seems like it should work.
Thanks