Hi I have the following bubble sort algorithm (generic code taken from another site) and I would like to have numbers next to each element of the array as it gets sorted. For example when I run it and it sorts out the array, next to each element it should have the number 1 as this is the first of many sorting algorithms I am using. So to demonstrate:
My results after sorting will look like:
4 1
27 1
54 1
321 1
542 1
654 1
887 1
1023 1
As you can see, the number 1 is inserted into the each element of the array as it is being sorted in the algorithm. Can someone help me with this?
Sorting algorithm:
public static <E extends Comparable<? super E>> void bubbleSort(E[] comparable) {
boolean changed = false;
do {
changed = false;
for (int a = 0; a < comparable.length - 1; a++) {
if (comparable[a].compareTo(comparable[a + 1]) > 0) {
E tmp = comparable[a];
comparable[a] = comparable[a + 1];
comparable[a + 1] = tmp;
changed = true;
}
}
} while (changed);
}
After you have sorted do the following to print: