• 队列


    队列是个先进先出的容器

    下面是个简单小列子

    package queue;
    
    
    import java.util.LinkedList;
    import java.util.Queue;
    import java.util.Random;
    /*
     * ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
     * @Directions 
     * @author ZhuangZi
     * @version $Id: QueueDemo.java,v 0.1 2013-9-16 下午5:20:17 ZhuangZi Exp $
     * ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
     */
    public class QueueDemo {
        /***
         * @Directions 测试队列先进先出
         * @author  ZhuangZi_http://www.hzdracom.com/
         * @class queue.QueueDemo
         * @method printQ
         * @date 2013-9-16下午5:25:06
         * @param queue void
         */
        public static void printQ(Queue queue) {
            System.out.println("queue长度是:"+queue.size() );
            while (queue.peek() != null) {
                System.out.println( ">>>>>>>移除"+queue.remove() );
    
    
            }
    
    
        }
        public static void main(String[] args) {
    //        向队列添加数字
    //        Queue<Integer> queue = new LinkedList<Integer>();
    //        Random rand = new Random(47);
    //        for (int i = 0; i < 10; i++)
    //            queue.offer(rand.nextInt(i + 10));
    //        printQ(queue);
            //向队列添加字母元素
            Queue<Character> qc = new LinkedList<Character>();
            for (char c : "abcdefg".toCharArray()){
                qc.offer(c);
                System.out.println( "++++添加"+c); 
            }
            printQ(qc);
    
    
        }
    }
    
  • 相关阅读:
    数组索引,内容交换
    查找两个等长升序线性表的中位数
    MarkDown使用小结
    java元注解
    LeetCode OJ:Valid Number
    LeetCode OJ:Insert Interval
    关于博客的格式
    9.Hive Metastore Administration
    3.控制hive map reduce个数
    6.capacity scheduler
  • 原文地址:https://www.cnblogs.com/riskyer/p/3325028.html
Copyright © 2020-2023  润新知