Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.patrickwaldie.project4;
- //Patrick Waldie
- //CSC161 - Computer Science II
- //December 13th, 2017
- //Project 4
- import java.util.*;
- import java.lang.System;
- public class Project4
- {
- Scanner scanner = new Scanner(System.in);
- static final int SIZE = 10000;
- public void main(String[] args)
- {
- Integer[] list = new Integer[SIZE];
- Integer[] temp = new Integer[SIZE];
- SearchSortAlgorithms<Integer> intSortObject = new SearchSortAlgorithms<Integer>();
- long startTime1;
- long startTime2;
- long startTime3;
- long startTime4;
- long endTime1;
- long endTime2;
- long endTime3;
- long endTime4;
- fillRandom(list);
- copyList(list, temp, SIZE);
- //Quick Sort: The pivot is the middle element.
- startTime1 = System.currentTimeMillis();
- intSortObject.quickSort(list, SIZE);
- endTime1 = System.currentTimeMillis();
- //Quick Sort: The pivot is the median element.
- copyList(temp, list, SIZE);
- startTime2 = System.currentTimeMillis();
- intSortObject.quickSortMedianPivot(list, SIZE);
- endTime2 = System.currentTimeMillis();
- //Quick Sort with insertion sort: The pivot is the middle element.
- copyList(temp, list, SIZE);
- startTime3 = System.currentTimeMillis();
- intSortObject.quickSortWithInsertionSort(list, SIZE);
- endTime3 = System.currentTimeMillis();
- //Quick sort with insertion sort: The pivot is the median element.
- copyList(temp, list, SIZE);
- startTime4 = System.currentTimeMillis();
- intSortObject.quickSortMedianWithInsertionSort(list, SIZE);
- endTime4 = System.currentTimeMillis();
- System.out.println("Quick sort time, with pivot middle element: " + (endTime1 - startTime1));
- System.out.println("Quick sort time, with pivot median element: " + (endTime2 - startTime2));
- System.out.println("Quick sort and insertion sort time, with pivot middle element: " + (endTime3 - startTime3));
- System.out.println("Quick sort and insertion sort time, with pivot median element: " + (endTime4 - startTime4));
- }
- public static void fillRandom(Integer[] list)
- {
- for (int index = 0; index < SIZE; index++)
- {
- list[index] = (int)(Math.random()*100000);
- }
- }
- public static void copyList(Integer[] list, Integer[] copyList, int length)
- {
- for (int index = 0; index < length; index++ )
- {
- copyList[index] = list[index];
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement