zoukankan      html  css  js  c++  java
  • 【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]
    



  • 相关阅读:
    englis translate,word
    三层架构 业务应用划分
    01 sharepoint 2010开发概述
    项目管理框架,生命周期与组织,管理过程,项目管理知识领,项目经理应具备的技能和素质
    New Text Document.udl
    03 sharepoint 2010 UI 改进
    WCF
    Sharepoint2010学习内容列表介绍
    测试概论,基础,ST评估与质量,ST过程与管理,应用负载压力测试
    ios NSDictionary 操作
  • 原文地址:https://www.cnblogs.com/mfrbuaa/p/5249381.html
Copyright © 2011-2022 走看看