I wrote a merge algorithm. When I run the following test:
public static void main(String[] args){
Integer[] arr = {3,7,9,11,0,-5,2,5,8,8,1};
List<Integer> list = new ArrayList<>();
list.addAll(Arrays.asList(arr));
List<Integer> result = mergesort(list);
System.out.println(result);
}
I get [-5, 0, 1, 2, 3, 5, 7, 8, 8, 9, 11]that is correct. However, I know that mergesort is a stable view, so how can I write a test that can prove that two 8 are in the order in which they were originally?
EDIT: Since I used the class Integer, not the primitive ints, I decided that I could just get it hashCode(), since it Integerextends the base class Object.
However, when I tried
Integer[] arr = {3,7,9,11,0,-5,2,5,8,8,1};
System.out.println(arr[8].hashCode());
System.out.println(arr[9].hashCode());
I only get:
8
8