/**
*
*/
package homework;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
public class Test {
public static void main(String[] args) {
System.out.println("ArrayList");
test2();
System.out.println("LinkedList");
test1();
}
public static void test1() {
long beginTime = System.currentTimeMillis();
for (int k = 0; k < 100000; k++) {
LinkedList<String> puKePai = new LinkedList<String>();
String[] huaSe = { "方块", "梅花", "红桃", "黑桃" };
String[] shuZi = { "A", "2", "3", "4", "5", "6", "7", "8", "9",
"10", "J", "Q", "K" };
// 买牌
puKePai.add("小王");
for (int i = 0; i < huaSe.length; i++) {
for (int j = 0; j < shuZi.length; j++) {
puKePai.add(huaSe[i] + shuZi[j]);
}
}
puKePai.add("大王");
// System.out.println(puKePai);
// 洗牌
Collections.shuffle(puKePai);
// 发牌
LinkedList<String> zhouRunFa = new LinkedList<String>();
LinkedList<String> liuDeHua = new LinkedList<String>();
LinkedList<String> zhouXinChi = new LinkedList<String>();
int zhangShu = (puKePai.size() - 3) / 3;
for (int i = 0; i < zhangShu; i++) {
zhouRunFa.add(puKePai.removeFirst());
liuDeHua.add(puKePai.removeFirst());
zhouXinChi.add(puKePai.removeFirst());
}
// System.out.println(zhouRunFa);
// System.out.println(liuDeHua);
// System.out.println(zhouXinChi);
// 看底牌
// System.out.println(puKePai);
}
long endTime = System.currentTimeMillis();
long time = endTime - beginTime;
System.out.println(time);
}
public static void test2() {
long beginTime = System.currentTimeMillis();
for (int k = 0; k < 100000; k++) {
ArrayList<String> puKePai = new ArrayList<String>();
String[] huaSe = { "方块", "梅花", "红桃", "黑桃" };
String[] shuZi = { "A", "2", "3", "4", "5", "6", "7", "8", "9",
"10", "J", "Q", "K" };
// 买牌
puKePai.add("小王");
for (int i = 0; i < huaSe.length; i++) {
for (int j = 0; j < shuZi.length; j++) {
puKePai.add(huaSe[i] + shuZi[j]);
}
}
puKePai.add("大王");
// System.out.println(puKePai);
// 洗牌
Collections.shuffle(puKePai);
// 发牌
ArrayList<String> zhouRunFa = new ArrayList<String>();
ArrayList<String> liuDeHua = new ArrayList<String>();
ArrayList<String> zhouXinChi = new ArrayList<String>();
int zhangShu = (puKePai.size() - 3) / 3;
for (int i = 0; i < zhangShu; i++) {
zhouRunFa.add(puKePai.remove(0));
liuDeHua.add(puKePai.remove(0));
zhouXinChi.add(puKePai.remove(0));
}
// System.out.println(zhouRunFa);
// System.out.println(liuDeHua);
// System.out.println(zhouXinChi);
// 看底牌
// System.out.println(puKePai);
}
long endTime = System.currentTimeMillis();
long time = endTime - beginTime;
System.out.println(time);
}
}
|
|