2014-06-11 3 views
1

비트 맵의 ​​배열을 겪는 코드를 작성하려고하지만 다른 배열에서 비트 맵이 이동되는 위치를 유지하고 싶습니다.안드로이드 Suffle 원래 위치를 유지 비트 맵의 ​​ArrayList

int[] ar = { 1, 2, 3, 7, 12, 4, 5, 13, 8, 9, 11, 10, 6 , 14, 15}; 
public static ArrayList<Bitmap> shuffleArray(int[] ar, ArrayList<Bitmap> arraybmorig) 
{ 
    Bitmap[] arraybmfinal = new Bitmap[arraybmorig.size()]; 

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

    arraybmfinal[ar[i]] = arraybmorig.get(i); 
    } 

    return new ArrayList(Arrays.asList(arraybmfinal)); 
} 

을하지만 내 코드가 비효율적이고 어떻게이이 기능을 할 수있는 최선의 방법입니다 ... [] AR 무작위 내 고정 배열하고자 다음과 같이 그렇게하기 위해, 내가 뭐하는 거지 ?

미리 예약 해주세요.

답변

0

ar 배열을 섞고 ar 위치에 비트 맵을 넣으려는 것으로 알고 있습니다.

private void ShuffleArray(int[] array) 
{ 
    int index, temp; 
    Random random = new Random(); 
    for (int i = array.length - 1; i > 0; i--){ 
     index = random.nextInt(i + 1); 
     temp = array[index]; 
     array[index] = array[i]; 
     array[i] = temp; 
    } 
} 

와 두 번째 방법 - ArrayList에 대한 사용의 기본 방법 : 당신은 배열 셔플 적어도 두 가지 방법이

ArrayList<Integer> x = new ArrayList<Integer>(); 
for(int i=1;i<=add.length();i++){ 
    x.add(i); 
} 
Collections.shuffle(x); 
+0

정말 내가 셔플 원하는 것은 ArrayList의 arraybmorig입니다, 내 편곡 []입니다 배열의 항목이 있어야하는 위치를 표시하는 유일한 방법입니다. – Billyjoker

+0

첫 번째 코드는 int []의 배열을 간단히 뒤섞습니다. 두 번째 코드는 항목이있는 위치를 모릅니다. – Billyjoker

+1

예. 그리고 int []의 배열을 뒤섞어서 비트 맵을 ar [0], ar [1] 등의 위치에 놓으십시오. –