数组实现队列
package com.atguigu.queue;
import java.util.Scanner;
public class ArrayQueueDemo {
public static void main(String[] args) {
ArrayQueue arrayQueue=new ArrayQueue(4);
char key=' ';
Scanner scanner=new Scanner(System.in);
boolean loop=true;
while (loop){
System.out.println("s(show): 显示队列");
System.out.println("e(show): 退出程序");
System.out.println("a(show): 添加数据到队列");
System.out.println("g(show): 获取数据");
System.out.println("h(show): 查看对头数据");
key=scanner.next().charAt(0);//接受一个字符
switch (key){
case 's':
try {
arrayQueue.showQueue();
}catch (Exception e){
System.out.println(e.getMessage());
}
break;
case 'a':
try{
System.out.println("输入一个数");
int value=scanner.nextInt();
arrayQueue.addQueue(value);
}catch (Exception e){
System.out.println(e.getMessage());
}
break;
case 'g':
try {
int res=arrayQueue.getQueue();
System.out.println("取出的数据是: "+res);