package com;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
/**
* Created with IntelliJ IDEA.
*
* @author: islc
* Date: 2022/4/7
* Time: 20:29
Queue<String> queue = new LinkedList<String>();
部分成员函数(包括继承的):
add(): 增加一个元索,如果队列已满,则抛出一个异常
remove(): 移除并返回队列头部的元素,如果队列为空,则抛出一个异常
element(): 返回队列头部的元素,如果队列为空,则抛出一个异常
offer(): 添加一个元素并返回 true,如果队列已满,则返回 false
poll(): 移除并返问队列头部的元素,如果队列为空,则返回 null
peek(): 返回队列头部的元素,如果队列为空,则返回 null
put(): 添加一个元素, 如果队列满,则阻塞
take(): 移除并返回队列头部的元素,如果队列为空,则阻塞
size(): 返回队列长度。
*/
public class c队列Queue {
// 初始化
static Queue<String> v=new LinkedList<String>();
static Queue<String> N=new LinkedList<String>();
// 主函数
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
String op,name,type;
int n=sc.nextInt();
for (int i = 0; i <n ; i++) {
op=sc.next();
if (op.contains("IN")){
name=sc.next();
type=sc.next();
if (type.contains("V")){
v.offer(name);
}else {
N.offer(name);
}
}else {
type=sc.next();
if (type.contains("V")){
v.poll();
}else {
N.poll();
}
}
}
while (v.size()!=0){
System.out.println(v.poll());
}
while (N.size()!=0){
System.out.println(N.poll());
}
}
}
JAVA数据结构_队列Queue_蓝桥杯_详解版
最新推荐文章于 2023-02-23 15:23:37 发布