/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package sort;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Random;
/**
*
* @author Paolo
*/
public class Main {
/**
* @param args the command line arguments
*/
System.
out.
print("Give me the sort method (merge/bubble/insert/gnome/quick): ");
sortMethod = read.readLine();
if (!SortMethod.validateMethod(sortMethod)) {
sortMethod = SortMethod.MERGE;
}
System.
out.
print("Give me the array size: ");
length
= Integer.
parseInt(read.
readLine());
System.
out.
print("Do you want insert random number in array? y/n ");
insert = read.readLine().charAt(0);
if (insert != 'y') {
for (int i = 0; i < length; i++) {
System.
out.
print("Give me the " + (i
+ 1) + " ° number: ");
array
[i
] = Integer.
parseInt(read.
readLine());
}
} else {
for (int i = 0; i < length; i++) {
array[i] = rand.nextInt(length);
}
}
System.
out.
print("Unsorted array: ");
for (int i = 0; i < length; i++) {
System.
out.
print(array
[i
] + " ");
}
long start
= System.
currentTimeMillis();
SortMethod met = SortMethod.forName(sortMethod);
array = met.sort(array);
long end
= System.
currentTimeMillis();
System.
out.
print("Sorted array: ");
for (int i = 0; i < array.length; i++) {
System.
out.
print(array
[i
] + " ");
}
System.
out.
println("Sort endend in: " + (end
- start
) + " millisec");
}
}