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

您的位置:首頁技術文章
文章詳情頁

Java 1.8使用數組實現循環隊列

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

本文實例為大家分享了Java 1.8使用數組實現循環隊列的具體代碼,供大家參考,具體內容如下

1、引入

使用數組實現循環隊列,功能如下:

1)isFull():隊列滿?2)isEmpty():隊列空?3)add():添加元素。4)pop():移除元素。5)display():展示隊列。6)getSize():獲取當前隊列元素個數。

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

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。

標簽: Java
相關文章:
主站蜘蛛池模板: 日韩三级在线免费观看 | 亚洲网在线观看 | 美女张开腿双腿让男人桶 | 欧美色成人tv在线播放 | 在线观看日本亚洲一区 | 特级毛片免费观看视频 | 日朝欧美亚洲精品 | 欧美一区二区日韩一区二区 | 欧美综合视频在线 | 最刺激黄a大片免费观看 | 亚洲午夜片 | 91热在线观看精品 | 日韩一区二区三区在线观看 | 久久精品国产99国产精品亚洲 | 一区二区三区视频免费观看 | 国产91丝袜在线播放九色 | 福利社色| 亚洲高清免费在线观看 | 曰本毛片va看到爽不卡 | 欧美成人久久一级c片免费 欧美成人看片黄a免费 | 精品精品国产自在久久高清 | 欧美成人性色生活片免费在线观看 | 久久精品亚洲综合一品 | 九九成人免费视频 | 日韩亚洲欧美一区噜噜噜 | 久久免费视频观看 | 久久99国产精品亚洲 | 手机免费在线看毛片 | 成人69| 免费一区在线观看 | 日韩99| 精品国产一区二区 | 亚洲欧美极品 | 欧美午夜不卡 | 一区免费在线观看 | 日本又黄又爽又免费 | 波多野结衣福利视频 | 国产男女视频在线观看 | 欧美aaa性bbb毛片 | 国产乱纶 | 日本免费三级网站 |