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 0000000000000000000000000000000000000000..ac75e466e07ac840b595ec05e916349df31929a3 --- /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 0000000000000000000000000000000000000000..383bfe39a5aa5ad85b41ca43f8b227bccc9ea5ae --- /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