JAVA40. 排队系统
描述
请设计一个排队程序,用户有普通客人和VIP客人之分,VIP客人不排队(即VIP客人在队列头部),目前队列中已有两位客人小明和小军在排队,请将VIP客人小红新增至队列头部。输入描述
无输出描述
预设代码中已经指定输出Java 解法, 执行用时: 6ms, 内存消耗: 9404KB, 提交时间: 2021-12-06
import java.util.*; public class Main { public static void main(String[] args) { Guest guest1 = new Guest("小明",false); Guest guest2 = new Guest("小军",false); Guest vipGuest = new Guest("小红",true); Deque<Guest> deque = new ArrayDeque<>(); deque.add(guest1); deque.add(guest2); //write your code here...... deque.addFirst(vipGuest); System.out.println(deque); } } class Guest{ String name; Boolean vip; @Override public String toString() { return name; } public Guest(String name, Boolean vip) { this.name = name; this.vip = vip; } }
Java 解法, 执行用时: 7ms, 内存消耗: 9164KB, 提交时间: 2021-12-05
import java.util.*; public class Main { public static void main(String[] args) { Guest guest1 = new Guest("小明",false); Guest guest2 = new Guest("小军",false); Guest vipGuest = new Guest("小红",true); Deque<Guest> deque = new ArrayDeque<>(); //write your code here...... deque.add(vipGuest); deque.add(guest1); deque.add(guest2); System.out.println(deque); } } class Guest{ String name; Boolean vip; @Override public String toString() { return name; } public Guest(String name, Boolean vip) { this.name = name; this.vip = vip; } }
Java 解法, 执行用时: 7ms, 内存消耗: 9308KB, 提交时间: 2021-11-29
import java.util.*; public class Main { public static void main(String[] args) { Guest guest1 = new Guest("小明",false); Guest guest2 = new Guest("小军",false); Guest vipGuest = new Guest("小红",true); Deque<Guest> deque = new ArrayDeque<>(); deque.add(guest1); deque.add(guest2); //write your code here...... if(vipGuest.vip==true){ deque.addFirst(vipGuest); }else{ deque.add(vipGuest); } System.out.println(deque); } } class Guest{ String name; Boolean vip; @Override public String toString() { return name; } public Guest(String name, Boolean vip) { this.name = name; this.vip = vip; } }
Java 解法, 执行用时: 7ms, 内存消耗: 9352KB, 提交时间: 2021-12-28
import java.util.*; public class Main { public static void main(String[] args) { Guest guest1 = new Guest("小明",false); Guest guest2 = new Guest("小军",false); Guest vipGuest = new Guest("小红",true); Deque<Guest> deque = new ArrayDeque<>(); //名称deque是“双端队列”的缩写 deque.add(guest1); deque.add(guest2); //write your code here...... //void addFirst(E e)插入此双端队列的前面, //如果它是立即可行且不会违反容量限制,抛出一个指定的元素IllegalStateException如果当前没有空间可用。 //当使用容量限制的deque时,通常最好使用方法offerFirst(E) 。 deque.addFirst(vipGuest); System.out.println(deque); } } class Guest{ String name; Boolean vip; @Override public String toString() { return name; } public Guest(String name, Boolean vip) { this.name = name; this.vip = vip; } }
Java 解法, 执行用时: 7ms, 内存消耗: 9432KB, 提交时间: 2021-12-08
import java.util.*; public class Main { public static void main(String[] args) { Guest guest1 = new Guest("小明",false); Guest guest2 = new Guest("小军",false); Guest vipGuest = new Guest("小红",true); Deque<Guest> deque = new ArrayDeque<>(); deque.add(guest1); deque.add(guest2); deque.addFirst(vipGuest);//write your code here...... System.out.println(deque); } } class Guest{ String name; Boolean vip; @Override public String toString() { return name; } public Guest(String name, Boolean vip) { this.name = name; this.vip = vip; } }