Solved

# sort items in an array

Posted on 2003-12-07

hi all.

I have an array , and I want to sort 3 items in that array(known values) in accending order without disterbing the others.for example if my array is

{ 1, 2, 20, 90, 30, 130, 10, 190 ,52 }

I want to sort three items contain 10, 20, 30 so the output would be

{ 1, 2, 10, 90, 20, 130, 30, 190 ,52 }. It sounds easy but I couldn't get it right.This is what I have done

public static void main(String[] args)

{

int[]num = { 1, 2, 20, 90, 30, 130, 10, 190 ,52 };

int temp;

for(int i =0; i<num.length; i++)

{

if (num[i] == 10)

{

temp = num[i];

for (int j=0; j<num.length; j++)

{

if (num[j] == 20)

{

num[i] = num[j];

num[j] = temp;

}

if (i == j)

num[i] = num[j];

}

}

}

for (int i =0; i<num.length; i++)

System.out.print (num[i] + " ");

}

}It doesn't do any thing good

Pease , anyone can show me a good way to dothis.

thank