zoukankan      html  css  js  c++  java
  • 队列

    队列是个先进先出的容器

    下面是个简单小列子

    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);
    
    
        }
    }
    
  • 相关阅读:
    springboot以jar运行时参数传递
    linux 下ab压力测试
    Quartus 11生成pof文件在AS烧写之后,程序无法启动
    芯片底层热焊盘的焊接
    CC3200模块的内存地址划分和bootloader,启动流程(二)
    python开发记录第一篇
    windows下使用Python出现No module named tkinter.ttk
    Pycharm设置Python的路径
    Qsys配置生成nios系统模块
    sprintf()函数使用异常
  • 原文地址:https://www.cnblogs.com/riskyer/p/3325028.html
Copyright © 2011-2022 走看看