Sorting problem

 DevX Home Today's Headlines   Articles Archive   Tip Bank   Forums

1. Registered User
Join Date
Sep 2006
Posts
23

## 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);
}```

2. Registered User
Join Date
Dec 2005
Posts
97
ah its because your outputting the hex address (i think thats what its called) and not the actual parts of the array

Code:
`System.out.println(array[i]);`

3. Registered User
Join Date
Sep 2006
Posts
23
that made it show out numbers but its showin 1
7
8
1
3
4
4
do u know whats wrong

4. Registered User
Join Date
Dec 2005
Posts
97
uh, well what is it supposed to do? i cant tell whats wrong from just your code.

5. Registered User
Join Date
Sep 2006
Posts
23
its supposed to use insertion sort and sort it from lowest to highest

6. Registered User
Join Date
Nov 2005
Posts
10
//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]);
}
}

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

 FAQ Latest Articles Java .NET XML Database Enterprise