//created a int rowCounter to be used
static int rowCount = 0;
public static void mailSort(int[] array)
{
int low = array[0];
int high = array[0];
int count = 0;
//added this
System.out.println("Row: " + rowCount);
rowCount++;
for(int i=0; i<array.length; i++)
{
int val = array[i];
if(val < low)
{low = val;}
if(val > high)
{high = val;}
}
int range = high - low +1; //Because we need to account for array index 0 later.
int[] holes = new int[range];
for(int i=0; i<array.length; i++)
{
int value = array[i] - low;
holes[value]++;
}
for(int i=0; i<holes.length; i++)
{
//System.out.println(holes[i]); <-- took this out so it would stop printing all those zeros
if(holes[i] != 0)//changed this to "!=" so as long as it wasn't zero, it would print out.
{
for(int j=0; j<holes[i]; j++)
{
array[count] = i + low;
System.out.println("The number " + (i+low) + " entered into position " + count);
count++;
}
}
}
return;
}
Great job to you for taking initiative to figure it out. Those headaches are the best because they teach you the most.

New Topic/Question
Reply



MultiQuote

|