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






本文转自mfrbuaa博客园博客,原文链接:http://www.cnblogs.com/mfrbuaa/p/5249381.html,如需转载请自行联系原作者
相关文章
C++ --priority_queue实现
1. 普通版本实现优先级队列 1.1 push()
66 0
Optional int parameter ‘id‘ is present but cannot be translated into a null value due to being ……
Optional int parameter ‘id‘ is present but cannot be translated into a null value due to being ……
324 0
|
索引
ES报错:“type“=>“cluster_block_exception“, “reason“=>“blocked by: [FORBIDDEN/12/index read-only / allow
ES报错:“type“=>“cluster_block_exception“, “reason“=>“blocked by: [FORBIDDEN/12/index read-only / allow
377 0
ES报错:“type“=>“cluster_block_exception“, “reason“=>“blocked by: [FORBIDDEN/12/index read-only / allow
MGA (Managed Global Area) Reference Note (Doc ID 2638904.1)
MGA (Managed Global Area) Reference Note (Doc ID 2638904.1)
335 0
SAP WM Storage Type Capacity Check Method 5 (Usage check based on SUT)
SAP WM Storage Type Capacity Check Method 5 (Usage check based on SUT)
SAP WM Storage Type Capacity Check Method 5 (Usage check based on SUT)
|
数据库 缓存 Linux
pacman usage
pacman使用 安装了系统时候, 应该立马使用pacman-mirrors -c China更新源, 再使用pacman -Syyn更新系统 编辑/etc/pacman.conf添加 [archlinuxcn] SigLevel = Optional TrustedOnly Server = https://mirrors.
2207 0
|
Docker 容器
Template parsing error: template: :1:2: executing at &lt;Volumes&gt;: map has no entry for key "Volume
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_34173549/article/details/80400454 报错: [root@ops-ip-statistic ~]# docker inspect -f {{.
2357 0
|
Unix Shell Linux