日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

未完成.队列

發(fā)布時(shí)間:2023/12/20 编程问答 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 未完成.队列 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
package 隊(duì)列queue;import java.util.LinkedList; import java.util.NoSuchElementException; import java.util.Queue;/*** * 創(chuàng)建時(shí)間:2017年12月8日 下午3:47:25 * 項(xiàng)目名稱:集合 * @author ukyozq * @version 1.0 * @since JDK 9.0 * 文件名稱:Queue_Test01.java * -----------------------------------------------------------------~ * 類說明:以下代碼顯示如何將鏈表用作 FIFO[*]隊(duì)列. * [*] First Input First Output 的縮寫,先入先出隊(duì)列, * 這是一種傳統(tǒng)的按序執(zhí)行方法,先進(jìn)入的指令先完成并引退,跟著才執(zhí)行第二條指令 -------------------------------------------------^_^---------------*/ public class Queue_Test01 {public static void main(String[] args){/*------------------------------------------------~LinkedList 和 PriorityQueue 是 Queue 接口的兩個(gè)實(shí)現(xiàn)類. LinkedList 還實(shí)現(xiàn)了 List 接口 --------------------------------------------------*/Queue<String> queue = new LinkedList<>();/*--------------------------------------------------~add() 如果可能,向隊(duì)列中添加一個(gè)元素.否則,它拋出異常. offer() will work the same as add() offer() 如果不能添加元素,則將元素添加到隊(duì)列中,而不拋出異常. 它在失敗時(shí)返回false,成功時(shí)返回true. ----------------------------------------------------*/queue.add("Apple");queue.offer("Select");queue.offer("Canada");queue.offer("X-man");System.out.println("Queue:"+queue);/*---------------------------------------------~Let's remove elements until the queue is empty | 讓我們 刪除 元素們 直到 那 隊(duì)列 為 空 | -----------------------------------------------*//*---------------------------------------------~[queue] ↓peek() |[10][9][8][7][6][5][4][3][2][1][0] |-> -> -> -> -> -> -> -> -> -> -> -> -> -> -> ->|-----------------------------------------------*/while(queue.peek() != null){System.out.println("Head Element:"+queue.peek());queue.remove();System.out.println("Removed one element from Queue.");System.out.println("Queue:"+queue);}/*----------------------------------------------------------~IsEmpty()是Java中用于判斷某種容器是否有元素的系統(tǒng)庫函數(shù)。 如用來判斷ArrayList,HashSet,HashMap是否有元素等。 peek() 返回隊(duì)列頂部,如果隊(duì)列為空而不是拋出異常,則返回null。 poll() 移除并返問隊(duì)列頭部的元素 。隊(duì)列為空不拋出異常,返回null。 ------------------------------------------------------------*/System.out.println("queue.isEmpty():"+queue.isEmpty());System.out.println("queue.peek():"+queue.peek());System.out.println("queue.poll():"+queue.poll());try{String str = queue.element();System.out.println("queue.element():"+str);str = queue.remove();System.out.println("queue.remove():"+str);} catch (NoSuchElementException e){ // e.printStackTrace();System.out.println("queue.remove(): Queue is empty.");}}}/*------------------------------------~~~~ 輸出: Queue:[Apple, Select, Canada, X-man] Head Element:Apple Removed one element from Queue. Queue:[Select, Canada, X-man] Head Element:Select Removed one element from Queue. Queue:[Canada, X-man] Head Element:Canada Removed one element from Queue. Queue:[X-man] Head Element:X-man Removed one element from Queue. Queue:[] queue.isEmpty():true queue.peek():null queue.poll():null queue.remove(): Queue is empty.----------------java---QQ群:215200319-----*/

?

轉(zhuǎn)載于:https://www.cnblogs.com/ukzq/p/8008079.html

總結(jié)

以上是生活随笔為你收集整理的未完成.队列的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。