Java??????????????????
???????????? ???????[ 2012/11/1 10:27:22 ] ????????
???????????????????????ó?100????????????Ч??????????????
??????????????????????HashMap??Ч??????????????HashSet??????????飬????ArrayList?????????????10000???????????????HashMap??????????0.05s??HashSet??0.07s?????????0.20s????ArrayList??0.25s??????????????????????????
?????????????????HashMap???????????????Ч??????????磬????????1-100??Щ????洢??????????У??????for?????????????????±???????????±????????????????????е????????????????????
import java.util.Random;
/**
* ???????λ?????
* @Description:
* @File: Demo4.java
* @Package None
* @Author Hanyonglu
* @Date 2012-10-18 ????06:54:06
* @Version V1.0
*/
public class Demo4 {
public static void main(String[] args) {
int values[] = new int[100];
int temp1??temp2??temp3;
Random r = new Random();
for(int i = 0;i < values.length;i++){
values[i] = i + 1;
}
//???????values.length??
for(int i = 0;i < values.length;i++){
temp1 = Math.abs(r.nextInt()) % (values.length-1); //??????????λ??
temp2 = Math.abs(r.nextInt()) % (values.length-1); //????????????λ??
if(temp1 != temp2){
temp3 = values[temp1];
values[temp1] = values[temp2];
values[temp2] = temp3;
}
}
// ???????鰱???????
for(int i = 0;i < 20;i++){
System.out.print(values[i] + " ");
if(( i + 1 ) % 10 == 0){
System.out.println("
");
}
}
}
}
?????????????????Ч??????????10000??????????????????????0.054s??
??????????????????????????????????任???????????????????????????????????
???????????????JAVA???????????????????????????????????????????????????????????????????????????????????????????????????????????á?
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11