网易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());
    }
}

 

posted on 2016-11-11 14:27  winters86  阅读(118)  评论(0编辑  收藏  举报