• 【DataStructure】Description and usage of queue


    【Description】

    A queue is a collection that implements the first-in-first-out protocal. This means that the only accessiable object in the collection in the first one that was inserted. The most common example of a queue is a waiting line. 

    【Interface】

       In the java Collections Framework includes a queue interface, which is implemented by four classes: the linkedList class, the AbstractQueue class, the priorityQUeue class, and the ArrayDeque class. For simple FIFO queues, the arrayDeque class the best choice:

    Queue<String> queue = new ArrayDeque<String>();

    【Demo】

    package com.albertshao.ds.queue;
    
    //  Data Structures with Java, Second Edition
    //  by John R. Hubbard
    //  Copyright 2007 by McGraw-Hill
    
    import java.util.*;
    
    public class TestStringQueue {
      public static void main(String[] args) {
        Queue<String> queue = new ArrayDeque<String>();
        queue.add("GB");
        queue.add("DE");
        queue.add("FR");
        queue.add("ES");
        System.out.println(queue);
        System.out.println("queue.element(): " + queue.element());
        System.out.println("queue.remove(): " + queue.remove());
        System.out.println(queue);
        System.out.println("queue.remove(): " + queue.remove());
        System.out.println(queue);
        System.out.println("queue.add("IE"): ");
        queue.add("IE");
        System.out.println(queue);
        System.out.println("queue.remove(): " + queue.remove());
        System.out.println(queue);
      }
    }

    【Result】

    [GB, DE, FR, ES]
    queue.element(): GB
    queue.remove(): GB
    [DE, FR, ES]
    queue.remove(): DE
    [FR, ES]
    queue.add("IE"): 
    [FR, ES, IE]
    queue.remove(): FR
    [ES, IE]
    



  • 相关阅读:
    taglib
    ThinkPHP魔术方法
    给图片添加文字
    公益筹模板
    清空(数据库+文件夹)
    php——文件下载
    查询上一个tp语句
    安装wampserver 2.5的时候出现丢失MSVCR100.dll的解决办法。
    ThinkPHP3.2.3 安装教程
    java基础——File类的基本用法
  • 原文地址:https://www.cnblogs.com/mfrbuaa/p/5249381.html
Copyright © 2020-2023  润新知