【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]

【DataStructure】Description and usage of queue的更多相关文章

  1. 【DataStructure】Description and Introduction of Tree

    [Description] At ree is a nonlinear data structure that models a hierarchical organization. The char ...

  2. 【DataStructure】One of queue usage: Simulation System

    Statements: This blog was written by me, but most of content  is quoted from book[Data Structure wit ...

  3. 【DataStructure】The description of Java Collections Framework

    The Java Connections FrameWork is a group of class or method and interfacs in the java.util package. ...

  4. 【DataStructure】Charming usage of Set in the java

    In an attempt to remove duplicate elements from list, I go to the lengths to take advantage of  meth ...

  5. 【Python】 多线程并发threading & 任务队列Queue

    threading python程序默认是单线程的,也就是说在前一句语句执行完之前后面的语句不能继续执行(不知道我理解得对不对) 先感受一下线程,一般情况下: def testa(): sleep(1 ...

  6. 数据结构【一】:简单队列simple queue

    简单的FIFO队列实现,非线程安全! 1.queue.h : abstract data type queue #ifndef CUR_QUEUE_H #define CUR_QUEUE_H #inc ...

  7. 【转】并发编程之Operation Queue

    http://blog.xcodev.com/blog/2013/10/28/operation-queue-intro/ 随着移动设备的更新换代,移动设备的性能也不断提高,现在流行的CPU已经进入双 ...

  8. 【ANT】description元素和属性

    <?xml version="1.0" ?> <project default="test"> <description> ...

  9. Python开发【笔记】:what?进程queue还能生产出线程!

    进程queue底层用线程传输数据 import threading import multiprocessing def main(): queue = multiprocessing.Queue() ...

随机推荐

  1. Eclipse中Cannot find any provider supporting DES解决之道

    原文出处:http://blog.csdn.net/darwinchina/article/details/12037999 异常: Caused by: java.security.NoSuchAl ...

  2. LVM管理

    一.步骤: 1.创建新的分区,并修改分区类型为8e 2.创建物理卷PV 3.将新建的PV添加到要扩展的VG中 4.用命令lvextend或lvresize来将新加入的PE添加到要扩展的LV中 5.用命 ...

  3. HTTP 503 错误 – 服务不可用 (Service unavailable)

    介绍 因暂时超载或临时维护,您的 Web 服务器目前无法处理 HTTP 请求. 其含义是, 这是一个暂时情况,会有一些延误, 过 后将会得到缓解. 有些服务器在这种情况下也许干脆拒绝套接字(socke ...

  4. CodeManage 源代码管理器v2.0发布

    下载地址 欢迎大家提出宝贵的意见和bug

  5. 开源项目Material Calendar View 学习记录 (一)

    开源项目Material Calendar View 学习记录 Github: https://github.com/prolificinteractive/material-calendarview ...

  6. Gson 简易笔记

    #Gson 简易笔记 之前用 fastjson.它连个规矩的文档都没有,而且在github的wiki上写着: gson的g可能是"龟"拼音的缩写,龟速的json库." 各 ...

  7. Javascript判断空对象

    最近在项目开发中判断空对象时,用了“!”运算符,结果程序出现bug,找了好久才找到原因. 其实自己范了一些低级错误,现在把自己经验总结一下: 在JavaScript中,任意JavaScript的值都可 ...

  8. web 调用OPC HRESULT:0x80070005 (E_ACCESSDENIED))

    除了配置DCOM外,还需要在web.config里面添加设置系统管理员权限的帐号和密码<identity impersonate="true" userName=" ...

  9. return 与 finally

    (function hello() { try { return console.log('return'); } catch (e) { } finally { console.log('final ...

  10. Qt Creator的配置

    说明:一直想入手QT,看了相关的教程也有一段时间了,但苦于安装QT编辑器一直没有成功,今天手痒痒,于是又来捣鼓一阵子,成功了,特记录下来,方便日后查阅: 环境:win7 x64  + QT Creat ...