import java.util.ArrayList;
import java.io.BufferedReader;
import java.io.*;
public class SortComparison
{
	static public void main(String[] args)
	{
		//we will only use one ArrayList data structure that we will empty after each sort
		ArrayList<Integer> list = new ArrayList<Integer>();
		String sortMethod="";
		//sortTime = the number of seconds that the sort takes
		int sortTime = 0;
		
		//we use a BufferedReader to read a string from the standard input
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		System.out.println("Choose the sorting method (insertion/selection): ");
		//the readLine() method may throw IOException so we enclose it in a try-catch block
		try {sortMethod = br.readLine();}
		catch(IOException e){System.out.println("The standard input is unavailable");}
		
		if (sortMethod.equalsIgnoreCase ("insertion"))
		{
			//we use the getList() method form the ReadFile class to get the numbers from input file
			ReadFile.getList(list, "input\\random5000.txt", 5000);
			//doInsertionSort() and doSelectionSort() methods from Sort class perform the sorting
			//and return the number of millisecods they lasted
			sortTime = Sort.doInsertionSort (list);
			//we output the result
			System.out.println ("\nRandom list with 5,000 elements...\t\t"+sortTime+" milliseconds");
			
			//we clear the current list to fill it with the new set of numbers to sort
			//and repeat the steps described above
			list.clear();ReadFile.getList(list, "input\\sorted5000.txt", 5000);
			sortTime = Sort.doInsertionSort (list);
			System.out.println ("\nSorted list with 5,000 elements...\t\t"+sortTime+" milliseconds");
			
			list.clear();ReadFile.getList(list, "input\\reversed5000.txt", 5000);
			sortTime = Sort.doInsertionSort (list);
			System.out.println ("\nReversed list with 5,000 elements...\t\t"+sortTime+" milliseconds");
			
			list.clear();ReadFile.getList(list, "input\\random10000.txt", 10000);
			sortTime = Sort.doInsertionSort (list);
			System.out.println ("\nRandom list with 10,000 elements...\t\t"+sortTime+" milliseconds");
			
			list.clear();ReadFile.getList(list, "input\\sorted10000.txt", 10000);
			sortTime = Sort.doInsertionSort (list);
			System.out.println ("\nSorted list with 10,000 elements...\t\t"+sortTime+" milliseconds");
			
			list.clear();ReadFile.getList(list, "input\\reversed10000.txt", 10000);
			sortTime = Sort.doInsertionSort (list);
			System.out.println ("\nReversed list with 10,000 elements...\t\t"+sortTime+" milliseconds");
			
			list.clear();ReadFile.getList(list, "input\\random20000.txt", 20000);
			sortTime = Sort.doInsertionSort (list);
			System.out.println ("\nRandom list with 20,000 elements...\t\t"+sortTime+" milliseconds");
			
			list.clear();ReadFile.getList(list, "input\\sorted20000.txt", 20000);
			sortTime = Sort.doInsertionSort (list);
			System.out.println ("\nSorted list with 20,000 elements...\t\t"+sortTime+" milliseconds");
			
			list.clear();ReadFile.getList(list, "input\\reversed20000.txt", 20000);
			sortTime = Sort.doInsertionSort (list);
			System.out.println ("\nReversed list with 20,000 elements...\t\t"+sortTime+" milliseconds");
			
			list.clear();ReadFile.getList(list, "input\\random50000.txt", 50000);
			sortTime = Sort.doInsertionSort (list);
			System.out.println ("\nRandom list with 50,000 elements...\t\t"+sortTime+" milliseconds");
			
			list.clear();ReadFile.getList(list, "input\\sorted50000.txt", 50000);
			sortTime = Sort.doInsertionSort (list);
			System.out.println ("\nSorted list with 50,000 elements...\t\t"+sortTime+" milliseconds");
			
			list.clear();ReadFile.getList(list, "input\\reversed50000.txt", 50000);
			sortTime = Sort.doInsertionSort (list);
			System.out.println ("\nReversed list with 50,000 elements...\t\t"+sortTime+" milliseconds");
		}
		else if (sortMethod.equalsIgnoreCase ("selection"))
		{
			//we do the same as above (for insertionSelection method)
			ReadFile.getList(list, "input\\random5000.txt", 5000);
			sortTime = Sort.doSelectionSort (list);
			System.out.println ("\nRandom list with 5,000 elements...\t\t"+sortTime+" milliseconds");
			
			list.clear();ReadFile.getList(list, "input\\sorted5000.txt", 5000);
			sortTime = Sort.doSelectionSort (list);
			System.out.println ("\nSorted list with 5,000 elements...\t\t"+sortTime+" milliseconds");
			
			list.clear();ReadFile.getList(list, "input\\reversed5000.txt", 5000);
			sortTime = Sort.doSelectionSort (list);
			System.out.println ("\nReversed list with 5,000 elements...\t\t"+sortTime+" milliseconds");
			
			list.clear();ReadFile.getList(list, "input\\random10000.txt", 10000);
			sortTime = Sort.doSelectionSort (list);
			System.out.println ("\nRandom list with 10,000 elements...\t\t"+sortTime+" milliseconds");
			
			list.clear();ReadFile.getList(list, "input\\sorted10000.txt", 10000);
			sortTime = Sort.doSelectionSort (list);
			System.out.println ("\nSorted list with 10,000 elements...\t\t"+sortTime+" milliseconds");
			
			list.clear();ReadFile.getList(list, "input\\reversed10000.txt", 10000);
			sortTime = Sort.doSelectionSort (list);
			System.out.println ("\nReversed list with 10,000 elements...\t\t"+sortTime+" milliseconds");
			
			list.clear();ReadFile.getList(list, "input\\random20000.txt", 20000);
			sortTime = Sort.doSelectionSort (list);
			System.out.println ("\nRandom list with 20,000 elements...\t\t"+sortTime+" milliseconds");
			
			list.clear();ReadFile.getList(list, "input\\sorted20000.txt", 20000);
			sortTime = Sort.doSelectionSort (list);
			System.out.println ("\nSorted list with 20,000 elements...\t\t"+sortTime+" milliseconds");
			
			list.clear();ReadFile.getList(list, "input\\reversed20000.txt", 20000);
			sortTime = Sort.doSelectionSort (list);
			System.out.println ("\nReversed list with 20,000 elements...\t\t"+sortTime+" milliseconds");
			
			list.clear();ReadFile.getList(list, "input\\random50000.txt", 50000);
			sortTime = Sort.doSelectionSort (list);
			System.out.println ("\nRandom list with 50,000 elements...\t\t"+sortTime+" milliseconds");
			
			list.clear();ReadFile.getList(list, "input\\sorted50000.txt", 50000);
			sortTime = Sort.doSelectionSort (list);
			System.out.println ("\nSorted list with 50,000 elements...\t\t"+sortTime+" milliseconds");
			
			list.clear();ReadFile.getList(list, "input\\reversed50000.txt", 50000);
			sortTime = Sort.doSelectionSort (list);
			System.out.println ("\nReversed list with 50,000 elements...\t\t"+sortTime+" milliseconds");
		}
		else System.out.println("Sorting method should be 'insertion' or 'selection'");
	}
}
