国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

Java 1.8使用數(shù)組實(shí)現(xiàn)循環(huán)隊(duì)列

瀏覽:9日期:2022-08-21 18:52:43

本文實(shí)例為大家分享了Java 1.8使用數(shù)組實(shí)現(xiàn)循環(huán)隊(duì)列的具體代碼,供大家參考,具體內(nèi)容如下

1、引入

使用數(shù)組實(shí)現(xiàn)循環(huán)隊(duì)列,功能如下:

1)isFull():隊(duì)列滿(mǎn)?2)isEmpty():隊(duì)列空?3)add():添加元素。4)pop():移除元素。5)display():展示隊(duì)列。6)getSize():獲取當(dāng)前隊(duì)列元素個(gè)數(shù)。

2、代碼

package DataStructure;import java.util.Arrays;/** * @author: Inki * @email: inki.yinji@qq.com * @create: 2020 1022 * @last_modify: 2020 1023 */public class MyArrayQueue<AnyType> { /** * The default max size of my array queue. */ private final int DEFAULT_MAX_SIZE = 10; /** * The max size of my array queue. */ private int maxSize; /** * The front of my array queue. */ private int front; /** * The rear of my array queue. */ private int rear; /** * Using array to simulate queue. */ private AnyType[] arrQueue; /** * The first constructor. */ public MyArrayQueue() { this(DEFAULT_MAX_SIZE); }//Of the first constructor /** * The second constructor. */ public MyArrayQueue(int paraMaxSize) { maxSize = paraMaxSize + 1; arrQueue = (AnyType[]) new Object[maxSize]; front = 0; rear = 0; }//Of the second constructor /** * Queue is full? * @return: * True if full else false. */ public boolean isFull() { return (rear + 1) % maxSize == front; }//Of isFull /** * Queue is empty? * @return: * True if empty else false. */ public boolean isEmpty() { return front == rear; }//Of isEmpty /** * Add element. * @param: * paraVal: * The given value. */ public void add(AnyType paraVal) { if(isFull()) { System.out.println('The queue is full.'); return; }//Of if arrQueue[rear] = paraVal; rear = (rear + 1) % maxSize; }//Of add /** * Pop element. */ public AnyType pop() { if (isEmpty()) { throw new RuntimeException('The queue is full.'); }//Of if AnyType retVal = arrQueue[front]; front = (front + 1) % maxSize; return retVal; }//of pop /** * Display array queue. */ public void display() { if (isEmpty()) { System.out.println('The queue is empty.'); return; }//Of if System.out.print('The queue is: ['); int i = front; while (i != (rear + maxSize- 1) % maxSize) { System.out.printf('%s, ', arrQueue[i]); i = (i + 1) % maxSize; }//Of while System.out.printf('%s]', arrQueue[rear - 1]); }//Of display /** * Get current size of my array queue. */ public int getSize() { return (rear - front + maxSize) % maxSize + 1; }//Of getSize /** * The main **/ public static void main(String[] args) { MyArrayQueue <Integer> testArrayQueue = new MyArrayQueue<>(3); testArrayQueue.add(1); testArrayQueue.add(2); testArrayQueue.add(4); testArrayQueue.pop(); testArrayQueue.display(); }//Of main}//Of MyArrayQueue

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。

標(biāo)簽: Java
相關(guān)文章:
主站蜘蛛池模板: 欧美a极品极品欧美 | 亚洲专区在线视频 | 国产成人毛片视频不卡在线 | 欧美视频一二三区 | 美女视频免费黄色 | 美女扒开双腿让男人桶 | 亚洲精品视频专区 | 亚洲在线免费观看 | xxxwww欧美| 搞黄网站免费观看 | 狠狠88综合久久久久综合网 | 怡红院免费的全部视频国产a | 亚洲的天堂 | 日本xxxxx久色视频在线观看 | 美日韩一区二区三区 | www.av在线.com | 免费一级a毛片在线播放视 免费一级α片在线观看 | 亚洲一区二区三区不卡在线播放 | 亚洲欧美另类视频 | 精品午夜国产在线观看不卡 | jizjizjiz亚洲人| 中国国语毛片免费观看视频 | 久热香蕉精品视频在线播放 | 国产呦在线观看视频 | 成年女人在线视频 | 精品精品国产欧美在线观看 | 免费女人18毛片a级毛片视频 | 国产成人自拍在线 | 久久精品视频一区二区三区 | 久久久久久全国免费观看 | 国内成人免费视频 | 作爱视频在线免费观看 | 亚洲性xx | 欧美日韩视频一区二区 | 女人叉开腿让男人捅 | 99视频精品免费99在线 | 91久久| 特黄日韩免费一区二区三区 | 国产成人精品免费 | 国产精品一级香蕉一区 | 美女黄页黄频 |