【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]
【DataStructure】Description and usage of queue的更多相关文章
- 【DataStructure】Description and Introduction of Tree
[Description] At ree is a nonlinear data structure that models a hierarchical organization. The char ...
- 【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 ...
- 【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. ...
- 【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 ...
- 【Python】 多线程并发threading & 任务队列Queue
threading python程序默认是单线程的,也就是说在前一句语句执行完之前后面的语句不能继续执行(不知道我理解得对不对) 先感受一下线程,一般情况下: def testa(): sleep(1 ...
- 数据结构【一】:简单队列simple queue
简单的FIFO队列实现,非线程安全! 1.queue.h : abstract data type queue #ifndef CUR_QUEUE_H #define CUR_QUEUE_H #inc ...
- 【转】并发编程之Operation Queue
http://blog.xcodev.com/blog/2013/10/28/operation-queue-intro/ 随着移动设备的更新换代,移动设备的性能也不断提高,现在流行的CPU已经进入双 ...
- 【ANT】description元素和属性
<?xml version="1.0" ?> <project default="test"> <description> ...
- Python开发【笔记】:what?进程queue还能生产出线程!
进程queue底层用线程传输数据 import threading import multiprocessing def main(): queue = multiprocessing.Queue() ...
随机推荐
- hdu 4666 Hyperspace
曼哈顿距离,两个点设为(x1,y1),(x2,y2),其距离为|x1-x2|+|y1-y2| #include <cstdio> #include <set> #include ...
- vue 使用总结
1.Vuejs组件 vuejs构建组件使用 Vue.component('componentName',{ /*component*/ }): 这里注意一点,组件要先注册再使用,也就是说: Vue.c ...
- [转载]aptitude与apt-get的区别和联系
转自 http://www.cnblogs.com/yuxc/archive/2012/08/02/2620003.html 命令 下面将要介绍的所有命令都需要sudo!使用时请将“packagena ...
- 创建和管理表【weber出品必属精品】
创建表 必须有 : 1. CREATE TABLE 的权限 SQL> conn /as sysdba 已连接. SQL> create user test default tablespa ...
- 45个非常有用的 Oracle 查询语句小结
45个非常有用的 Oracle 查询语句小结 这里我们介绍的是 40+ 个非常有用的 Oracle 查询语句,主要涵盖了日期操作,获取服务器信息,获取执行状态,计算数据库大小等等方面的查询.这些是所有 ...
- OpenGL ES 2.0 混合
混合技术 混合技术就是将俩个片元调和,主要用于将通过各项测试准备进入帧缓冲的片元(源片元)与原有片元按照设定的比例加权计算出最终片元的颜色值. OpenGL ES 2.0中是通过设置混合因子来指定两个 ...
- poj3301 三分
Texas Trip Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4998 Accepted: 1559 Descri ...
- [Leetcode] Merge Sorted Array (C++)
我在Github上新建了一个解答Leetcode问题的Project, 大家可以参考, 目前是Java 为主,里面有leetcode上的题目,解答,还有一些基本的单元测试,方便大家起步. 题目: Gi ...
- sql 用openxml 将xml转换为数据表Table
CREATE PROCEDURE up_OpenXml ( @xml XML ) AS BEGIN DECLARE @Pointer INT EXECUTE sp_xml_preparedocumen ...
- php中利用HttpClient判断页面状态
$url = ''; $info = parse_url($url); $httpClient = new HttpClient($info['host']); $httpClient->get ...