【DataStructure】Description and usage of queue
来源:互联网 发布:清华大学网络空间安全 编辑:程序博客网 时间:2024/04/27 23:37
【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-Hillimport 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(): GBqueue.remove(): GB[DE, FR, ES]queue.remove(): DE[FR, ES]queue.add("IE"): [FR, ES, IE]queue.remove(): FR[ES, IE]
0 0
- 【DataStructure】Description and usage of queue
- 【DataStructure】The description and usage of Stack
- 【DataStructure】One of queue usage: Simulation System
- 【DataStructure】Descriptioin and usage of List
- 【DataStructure】Description and Introduction of Tree
- usage of stack and queue
- 【DataStructure】Another usage of List: Polynomial
- 【DataStructure】Another usage of Map: Concordance
- 【DataStructure】The description of Java Collections Framework
- 【DataStructure】The description of generic collections
- 【DataStructure】Charming usage of Set in the java
- usage of >>>、>> and << operators
- 队列的构造以及使用方法(the usage and construction of queue)
- Usage of get_fs and set_fs
- Usage of typedef and define
- Usage of AWR And ASH
- usage of javasigner and keytool
- usage of list and iterator
- 人民网 英超造就美丽法国
- 听音训练手册--音频制品与听评
- ini_set、php_value、php_flag、php_admin_value、php_admin_flag修改php.ini参数
- 常用类——时间处理总结
- win32打印机控制,API打印操作
- 【DataStructure】Description and usage of queue
- 关于css的盒子模型
- HDU 1527 取石子游戏 威佐夫博弈
- Android开发系列之ListView
- SQL语言和常用函数
- LDAP配制
- pat解题报告【1076】
- NOI2014 随机数生成器
- loop设备