国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

佳明面試-洗牌算法

2019-11-06 06:01:59
字體:
來源:轉載
供稿:網友

一副牌52張,考慮時間復雜度和空間復雜度。

//初始化撲克牌 int[] source = new int[52]; for (int i = 1; i <= 52; i++) { source[i - 1] = i; } int[] res = new int[52]; Random random = new Random(); int index = 0; int lastIndex = source.length - 1; //洗牌開始 while (true) { if (lastIndex == 0) { index = 0; } else { index = random.nextInt(lastIndex); //生成[0,lastIndex]之間的隨機數 } Integer value = source[index]; source[index] = source[lastIndex]; res[lastIndex]=value; if (lastIndex == 0) { break; } lastIndex--; } //打印結果 for (int i = 0; i < res.length; i++) { System.out.PRintln(res[i]); } }
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 绍兴市| 松桃| 文登市| 靖州| 塔河县| 资源县| 乌拉特前旗| 岳阳市| 五寨县| 广丰县| 祁东县| 九龙城区| 泗水县| 华池县| 元朗区| 康马县| 儋州市| 满城县| 伽师县| 伊宁县| 本溪市| 山阴县| 布尔津县| 阿克苏市| 九台市| 阳山县| 平泉县| 澄迈县| 禹州市| 长寿区| 康马县| 丰顺县| 元江| 永春县| 海林市| 常山县| 金堂县| 那坡县| 沧源| 长岭县| 南平市|