网易2017 洗牌
package com.net163.question; import org.junit.Test; import java.util.Stack; /** * Created by Administrator on 2016/11/11 0011. */ public class Card { private int card[] = {1, 2, 3, 4, 5, 6}; @Test public void randomCard() { Stack<Integer> leftStack = new Stack<Integer>(); Stack<Integer> rightStack = new Stack<Integer>(); for (int i = 0; i < 3; i++) { leftStack.push(card[i]); rightStack.push(card[card.length/2+i]); } int i = 0; while (!leftStack.isEmpty()) { card[i] = rightStack.pop(); card[++i] = leftStack.pop(); i++; } Stack<Integer> tempStack = new Stack<Integer>(); for(int x :card) tempStack.push(x) ; while (!tempStack.isEmpty()) System.out.print(tempStack.pop()); } }
版权声明:本文为winters1992原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。