From 65b17857b693d55fac759f332555525a9951d954 Mon Sep 17 00:00:00 2001 From: asus <13860948875> Date: Sat, 2 Jan 2021 22:16:42 +0800 Subject: [PATCH] 12 --- "\344\275\234\344\270\232/1.2.txt" | 62 ++++++++++++++++++++++++++++++ "\344\275\234\344\270\232/1.3.txt" | 21 ++++++++++ 2 files changed, 83 insertions(+) create mode 100644 "\344\275\234\344\270\232/1.2.txt" create mode 100644 "\344\275\234\344\270\232/1.3.txt" diff --git "a/\344\275\234\344\270\232/1.2.txt" "b/\344\275\234\344\270\232/1.2.txt" new file mode 100644 index 0000000..ac75e46 --- /dev/null +++ "b/\344\275\234\344\270\232/1.2.txt" @@ -0,0 +1,62 @@ +package program; + +public class MyQueue { + private int [] queArray; + private int maxSize; + public int front; + public int rear; + public static int length; + + //初始化队列 + public MyQueue(int maxSize) { + this.maxSize = maxSize; + queArray = new int[maxSize]; + front = 0; + rear = -1; + length = 0; + } + //插入 + public void InsertQueue(int item) { + if(isFull()) { + System.out.println("队列已满"); + } + if(rear == maxSize-1) { + rear = -1; + } + queArray[++rear] = item; + length++; + } + + //删除队列元素 + public int RemoveQueue() { + if(isEmpty()) { + System.out.println("队列为空"); + } + if(front == maxSize) { + front = 0; + } + int item = queArray[front++]; + length--; + return item; + } + //查看对头元素 + public int PeekQueue() { + if(isEmpty()) { + System.out.println("队列为空"); + } + return queArray[front]; + } + + //队列长度 + public int size() { + return length; + } + + //判断空 + public boolean isEmpty() { + return (length == 0); + } + //判断满 + public boolean isFull() { + return (length == maxSize); + } \ No newline at end of file diff --git "a/\344\275\234\344\270\232/1.3.txt" "b/\344\275\234\344\270\232/1.3.txt" new file mode 100644 index 0000000..383bfe3 --- /dev/null +++ "b/\344\275\234\344\270\232/1.3.txt" @@ -0,0 +1,21 @@ +package program; + +public class Queue_main { + + public static void main(String[] args) { + // TODO ×Ô¶¯Éú³ÉµÄ·½·¨´æ¸ù + MyQueue que = new MyQueue(10); + que.InsertQueue(1); + que.InsertQueue(2); + que.InsertQueue(3); + que.InsertQueue(4); + que.InsertQueue(5); + que.InsertQueue(6); + que.InsertQueue(7); + System.out.println(que.PeekQueue()); + System.out.println(que.length); + System.out.println(que.RemoveQueue()); + System.out.println(que.PeekQueue()); + } + +} \ No newline at end of file -- Gitee