Quoted:
I'm not asking anyone to do my homework for me.... I've already spent close to 5 hoursworking on this piece of code.
I did pretty good in my first JAVA class, but my prof for this semesters class is VERY new to teaching (he JUST graduated...
) and isn't very good at explaining things. We're basically learning this on our own.
Anyway..... the code posted is what I've put together based on examples from about 6 different JAVA help sites. It compiles OK, but throws an error at the call to pigeon_sort. I understand that it's trying to access an index out of bounds of the array, but don't see where...
Guys, ANY advice would be helpful.
ETA: Thank you, allenNH. neither of my professors EVER covered that particaular structuring of an incrementer and I couldn't find a good explanation online.
Ok, here's a bit more for you to chew on. This:
public static int[] pigeon_Sort(int[] arr)
{
int i, j;
int[] count = new int[arr.length];
for(i = 0; i < arr.length; i++ )
{
count[arr[i]]++;
}
You are looping through the array 'arr', but you are accessing the array 'count' inside the loop. This is the source of your problem.
ETA:
int array[] = {24,17,6,35,11,119,7,79};
int[] count = new int[arr.length];
Here you are saying that count has 8 elements (0..7). In the loop, you're trying to access count[arr[i]] the first time through.
count[arr[i]] = count[arr[0]] = count[24]