im looking for a way to print the array as is after each pass. this is the sort code i have so far. its a basic implementation of the bubble sort algorithm that prints out the original state of the array and the sorted state
public class bubbleSortTest
{
public static void main(String a[])
{
int i;
int array[] = {90, 8, 7, 56, 123, 235, 9, 1, 653};
System.out.println("Values Before the sort:\n");
for(i = 0; i < array.length; i++)
System.out.print( array[i]+" ");
System.out.println();
bubble_srt(array, array.length);
System.out.print("Values after the sort:\n");
for(i = 0; i <array.length; i++)
System.out.print(array[i]+" ");
System.out.println();
System.out.println("PAUSE");
}
public static void bubble_srt( int a[], int n )
{
int i, j,t=0;
for(i = 0; i < n; i++)
{
for(j = 1; j < (n-i); j++)
{
if(a[j-1] > a[j])
{
t = a[j-1];
a[j-1]=a[j];
a[j]=t;
}
}
}
}
}
Add a new for loop inside the outer loop of sorting to print the values after each pass.