Advertisement
Guest User

Untitled

a guest
Dec 14th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.62 KB | None | 0 0
  1. package com.patrickwaldie.project4;
  2.  
  3. //Patrick Waldie
  4. //CSC161 - Computer Science II
  5. //December 13th, 2017
  6. //Project 4
  7.  
  8.  
  9. import java.util.*;
  10. import java.lang.System;
  11.  
  12. public class Project4
  13. {
  14. Scanner scanner = new Scanner(System.in);
  15. static final int SIZE = 10000;
  16.  
  17. public void main(String[] args)
  18. {
  19.  
  20. Integer[] list = new Integer[SIZE];
  21. Integer[] temp = new Integer[SIZE];
  22.  
  23. SearchSortAlgorithms<Integer> intSortObject = new SearchSortAlgorithms<Integer>();
  24.  
  25. long startTime1;
  26. long startTime2;
  27. long startTime3;
  28. long startTime4;
  29.  
  30. long endTime1;
  31. long endTime2;
  32. long endTime3;
  33. long endTime4;
  34.  
  35. fillRandom(list);
  36. copyList(list, temp, SIZE);
  37.  
  38. //Quick Sort: The pivot is the middle element.
  39. startTime1 = System.currentTimeMillis();
  40. intSortObject.quickSort(list, SIZE);
  41. endTime1 = System.currentTimeMillis();
  42.  
  43.  
  44. //Quick Sort: The pivot is the median element.
  45. copyList(temp, list, SIZE);
  46. startTime2 = System.currentTimeMillis();
  47. intSortObject.quickSortMedianPivot(list, SIZE);
  48. endTime2 = System.currentTimeMillis();
  49.  
  50. //Quick Sort with insertion sort: The pivot is the middle element.
  51. copyList(temp, list, SIZE);
  52. startTime3 = System.currentTimeMillis();
  53. intSortObject.quickSortWithInsertionSort(list, SIZE);
  54. endTime3 = System.currentTimeMillis();
  55.  
  56. //Quick sort with insertion sort: The pivot is the median element.
  57. copyList(temp, list, SIZE);
  58. startTime4 = System.currentTimeMillis();
  59. intSortObject.quickSortMedianWithInsertionSort(list, SIZE);
  60. endTime4 = System.currentTimeMillis();
  61.  
  62. System.out.println("Quick sort time, with pivot middle element: " + (endTime1 - startTime1));
  63. System.out.println("Quick sort time, with pivot median element: " + (endTime2 - startTime2));
  64. System.out.println("Quick sort and insertion sort time, with pivot middle element: " + (endTime3 - startTime3));
  65. System.out.println("Quick sort and insertion sort time, with pivot median element: " + (endTime4 - startTime4));
  66.  
  67. }
  68.  
  69. public static void fillRandom(Integer[] list)
  70. {
  71. for (int index = 0; index < SIZE; index++)
  72. {
  73. list[index] = (int)(Math.random()*100000);
  74. }
  75. }
  76.  
  77. public static void copyList(Integer[] list, Integer[] copyList, int length)
  78. {
  79. for (int index = 0; index < length; index++ )
  80. {
  81. copyList[index] = list[index];
  82. }
  83. }
  84.  
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement