【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() ...
随机推荐
- c#中关于virtual,override和new的理解
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Cons ...
- sql server 2008 中的架构(schame)理解
机构是属于数据库里面的.在一个数据库中,每一张表都属于一个架构,架构就像是命名空间,把数据库中的表分成不同的组,一个组就是一个命名空间,方便管理
- 将宿主机东西拷贝到dokcer容器中去
1,获取容器名称或者id : docker ps 2,获取整个容器的id,其实键盘tag就可以补全的. docker inspect -f '{{.Id}}' 步骤A获取的名称或者id 3,在主机 ...
- (转)简易WCF负载均衡方案
最近跟高老师讨论nginx跟tomcat集群做负载均衡方案.感觉很有意思.想到自己项目中服务用的WCF技术,于是就想WCF如何做负载均衡,Google了一会,发现wcf4.0的路由服务好像可以实现.不 ...
- (转)用Eclipse编译你的ROS程序
原地址: http://blog.csdn.net/sujun3304/article/details/18572017 好了,理解了系统各个组件的含义后,还是直接进入程序真刀真枪的从实践中学习吧! ...
- php 对问卷结果进行统计
背景: 由于具体工作的原因,我做了一份纸质的问卷调查表,调查表的主要内容是让用户对10项要求(编号为A,B....)进行优先级排序,所以我得到的结果是好几百份类似于A>I>H>G&g ...
- CSS的权重(转)
CSS写的渐渐多了,他的权重问题就不得不昂首面对,之前一直得过且过的将就用着,直到最近遇到了几个大坑,一直割刺着我对前端的热情,得了得了,蒙不过去了,就发点时间记下来吧,当然还是一片转载的文章,有时候 ...
- UIP协议栈
UIP协议栈笔记 http://blog.chinaunix.net/uid-23247944-id-2974928.html
- Funny String
def main(): t = int(raw_input()) for _ in xrange(t): s = raw_input().strip() s_len = len(s) is_funny ...
- 函数:Python的乐高积木 - 零基础入门学习Python017
函数:Python的乐高积木 让编程改变世界 Change the world by program 相信大家小时候应该都玩过神奇的乐高积木,只要通过想象和创意,我们可以用它拼凑出很多神奇的东西. 随 ...