Some Efficient Algorithms

1. For Integer,you can consider the following:

  *2   <<1 

  /2  ≡ >>1

  %2  ≡  &1

2. Generate a non-repeating numbers random array ranging from 1-50

     int[] result = new int[50];
        ArrayList<Integer> numPool = new ArrayList<Integer>();
        for (int i = 0; i < 50; i++) {
            numPool.add(i);
        }
        Random random = new Random();
        for(int j=0;j<50;j++){
            int index = random.nextInt(numPool.size());
            result[j]=numPool.get(index);
            numPool.remove(index);
        } 

or you can random sort the numPool

posted @ 2012-08-14 10:45  Qiengo  阅读(126)  评论(0编辑  收藏  举报