Advertisement
icyeti

Untitled

May 20th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.11 KB | None | 0 0
  1. import java.util.ArrayList;
  2.  
  3. public class Mergesort {
  4.  
  5. /**
  6. * Sorts list given using the mergesort algorithm
  7. * @param list the list to be sorted
  8. * @param first the index of the first element of the list to be sorted
  9. * @param last the index of the last element of the list to be sorted
  10. */
  11. public static void mergesort(ArrayList<Comparable> list, int first, int last){
  12. if (last - first == 1)
  13. {
  14. if(list.get(first).compareTo(list.get(last)) > 0)
  15. {
  16. Comparable temp = list.get(first);
  17. list.set(first, list.get(last));
  18. list.set(last, temp);
  19. }
  20. }
  21.  
  22. }
  23.  
  24.  
  25. /**
  26. * Merges two ordered sublists.
  27. *
  28. * PRE-CONDITION: list from first to mid-1 is in order, list from mid to last is in order
  29. * POST-CONDITION: list from first to last is in order
  30. *
  31. * @param list the list containing the ordered sublist
  32. * @param first first element of the first sublist
  33. * @param mid first element of the second sublist
  34. * @param last last element of the second sublist
  35. */
  36. public static void merge(ArrayList<Comparable> list, int first, int mid, int last){
  37.  
  38. }
  39.  
  40. public static void main(String[] args) {
  41.  
  42. }
  43.  
  44.  
  45. //================================================
  46. //======= HELPER METHODS FOR TESTING BELOW =======
  47. //================================================
  48.  
  49.  
  50. /**
  51. * Returns true if two lists have the same elements.
  52. *
  53. * @param orig the original list
  54. * @param copy the copy of the list
  55. *
  56. * @return true if orig and copy have the same number of each element, false otherwise
  57. */
  58. private static boolean sameElements(ArrayList<Comparable> orig, ArrayList<Comparable> copy){
  59.  
  60. }
  61.  
  62. /**
  63. * Returns true if list is in ascending order
  64. *
  65. * @param list the list to check for ordering
  66. *
  67. * @return true if list is in ascending order, false otherwise
  68. */
  69. private static boolean inOrder(ArrayList<Comparable> list){
  70.  
  71. }
  72.  
  73. /**
  74. * Returns a deep copy of the given list
  75. *
  76. * @param list the list to be copied and return
  77. *
  78. * @return deep copy of argument list
  79. */
  80. private static ArrayList<Comparable> copyList(ArrayList<Comparable> list){
  81.  
  82. }
  83.  
  84. /**
  85. * Returns a list of Strings
  86. *
  87. * @param length the number of elements the list is to have
  88. *
  89. * @return a list of String elements with length size
  90. */
  91. private static ArrayList<Comparable> listOfStrings(int length){
  92.  
  93. }
  94.  
  95. /**
  96. * Returns a list of Integers
  97. *
  98. * @param low the minimum number in the range of elements
  99. * @param high the maximum number in the range of elements
  100. * @param length the number of elements the list is to have
  101. *
  102. * @return a list of Integer elements with length size
  103. */
  104. private static ArrayList<Comparable> listOfInts(int low, int high, int length){
  105.  
  106. }
  107.  
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement