Sorting problem


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 6 of 6

Thread: Sorting problem

  1. #1
    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. #2
    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

    change your system.out.println(array) to:
    Code:
    System.out.println(array[i]);

  3. #3
    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. #4
    Join Date
    Dec 2005
    Posts
    97
    uh, well what is it supposed to do? i cant tell whats wrong from just your code.

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

  6. #6
    Join Date
    Nov 2005
    Posts
    10

    Smile

    //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]);
    }
    }

Similar Threads

  1. a very weird problem (AGAIN!!!)
    By Michael in forum ASP.NET
    Replies: 14
    Last Post: 02-24-2006, 09:54 AM
  2. Problem with sorting algorithm
    By MM4o in forum C++
    Replies: 1
    Last Post: 02-22-2006, 05:00 PM
  3. Josephus Problem, problem.
    By aesoprock00 in forum Java
    Replies: 2
    Last Post: 01-28-2006, 07:18 PM
  4. heap sorting problem
    By java? in forum Java
    Replies: 1
    Last Post: 11-28-2005, 09:23 PM
  5. Replies: 0
    Last Post: 12-13-2001, 01:06 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center