-
Sorting problem
why does this code show the ouput
[I@10b62c9
[I@10b62c9
[I@10b62c9
[I@10b62c9
[I@10b62c9
[I@10b62c9
[I@10b62c9
if you could fix it i wouild appreciate it
Code:
public static void swap(int[]a)
{
int i,n,atemp;
for(n=1;n<a.length;n++)
{
atemp=a[n];
i=n;
while(i>0&&atemp<a[i-1])
{
i--;
}
a[i]=atemp;
}
}
public static void main(String[]args)
{
int[]array={10,7,8,1,3,9,4};
swap(array);
for(int i=0;i<array.length;i++)
System.out.println(array);
}
-
ah its because your outputting the hex address (i think thats what its called) and not the actual parts of the array
change your system.out.println(array) to:
Code:
System.out.println(array[i]);
-
that made it show out numbers but its showin 1
7
8
1
3
4
4
do u know whats wrong
-
uh, well what is it supposed to do? i cant tell whats wrong from just your code.
-
its supposed to use insertion sort and sort it from lowest to highest
-
//try this
class test{
public static void insertionSort(int numbers[], int array_size)
{
int i, j, index;
for (i=1; i < array_size; i++)
{
index = numbers[i];
j = i;
while ((j > 0) && (numbers[j-1] > index))
{
numbers[j] = numbers[j-1];
j = j - 1;
}
numbers[j] = index;
}
}
public static void main(String[]args)
{
int[]array={10,7,8,1,3,9,4};
insertionSort(array,array.length);
for(int i=0;i<array.length;i++)
System.out.println(array[i]);
}
}