Head and Tail of the Queue#

Head and Tail of the Queue

https://www.nowcoder.com/practice/4acc8bb985b84b68b935ce26c8f4d1b9

import java.util.ArrayDeque;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        ArrayDeque deque = new ArrayDeque();

        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            String name = scanner.next();
            // 初始化队列中的数据
            deque.offerLast(name);
        }

        // write your code here......
        int i = 0;
          while(!deque.isEmpty()){
            if(i%2 == 0){
              System.out.println(deque.pollFirst());      
            }else{
              System.out.println(deque.pollLast());
            }
            i++;
          }

    }

}

全部评论

相关推荐

给我发了笔试链接,想着等晚上回去做,结果还没做流程就终止了
伟大的小黄鸭在学习:我猜就是笔试几乎没用,就是用来给用人部门拖时间复筛简历的,可能用人部门筛到你简历觉得不合适就提前挂了
投递小鹏汽车等公司10个岗位
点赞 评论 收藏
分享
彧未sr:查看图片
投递牧原集团等公司10个岗位
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-29 11:57
投递浪潮等公司10个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务